TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-29-2008, 04:06 PM   #1 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default I want to login to a website using PHP?

Right well I want to learn how to login to a website, and stay logged in to get some content from a page. How would I start off with this?
__________________
PHP/XHTML Freelancer:
Cleanscript.com v3 - Programming starting at just $5 act now!
Nor is offline  
Reply With Quote
Old 02-29-2008, 04:40 PM   #2 (permalink)
The Wanderer
 
serversphere's Avatar
 
Join Date: Dec 2006
Location: USA
Posts: 21
Thanks: 0
serversphere is on a distinguished road
Default

To clarify, do you mean you want to have PHP log into a website and grab content for you [in which case, have a look at cURL] or do you mean you want your site to allow people to log in and show them special content only when they are logged in?
Send a message via AIM to serversphere
serversphere is offline  
Reply With Quote
Old 02-29-2008, 04:43 PM   #3 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default

I want to have php login to a website and grab content. cURL you say? Say when I use cURL to submit the form how can I send back to the website after a successful login whats the process.. of staying logged in?
__________________
PHP/XHTML Freelancer:
Cleanscript.com v3 - Programming starting at just $5 act now!
Nor is offline  
Reply With Quote
Old 02-29-2008, 05:12 PM   #4 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default

I think I found good Drupal tutorial that basically explains the use of how to do this using the cookie jar:

Tutorial: Using php and curl to automate drupal tasks such as node adding or user adding | drupal.org
__________________
PHP/XHTML Freelancer:
Cleanscript.com v3 - Programming starting at just $5 act now!
Nor is offline  
Reply With Quote
The Following User Says Thank You to Nor For This Useful Post:
DeMo (02-29-2008)
Old 02-29-2008, 05:20 PM   #5 (permalink)
The Wanderer
 
serversphere's Avatar
 
Join Date: Dec 2006
Location: USA
Posts: 21
Thanks: 0
serversphere is on a distinguished road
Default

Also check out PHP/CURL - using libcurl with PHP

curl will allow you save session data to a local file so you can keep a login sesson alive. It also supports POSTing, so you can automatically push form data if needed to accomplish tasks on a website. We use it here for automatically submitting reboot requests to some datacenters without the need for our admins to have to manually login and submit the request. They push one button and the request is submitted for our client. It can be quite powerful.
Send a message via AIM to serversphere
serversphere is offline  
Reply With Quote
The Following 2 Users Say Thank You to serversphere For This Useful Post:
DeMo (02-29-2008), Nor (02-29-2008)
Old 02-29-2008, 05:21 PM   #6 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default

Thanks, I'll look into it.
__________________
PHP/XHTML Freelancer:
Cleanscript.com v3 - Programming starting at just $5 act now!
Nor is offline  
Reply With Quote
Old 02-29-2008, 05:23 PM   #7 (permalink)
The Wanderer
 
serversphere's Avatar
 
Join Date: Dec 2006
Location: USA
Posts: 21
Thanks: 0
serversphere is on a distinguished road
Default

YW and good luck! Let us know how you make out.
Send a message via AIM to serversphere
serversphere is offline  
Reply With Quote
Old 02-29-2008, 05:46 PM   #8 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default

Will do :) might make a article from my experience for talkphp :P
__________________
PHP/XHTML Freelancer:
Cleanscript.com v3 - Programming starting at just $5 act now!
Nor is offline  
Reply With Quote
Old 03-02-2008, 11:29 AM   #9 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Why not use stream_context_create ??

php Code:
$url = 'http://www.tibia.com/logging/url'; // The URL to the accountmanagement page
$f1 = 'accnr'; // Name of field1(ON THE WEBSITE YOU'RE TRYING TO LOGIN ON!)
$f2 = 'pass'; // Name of field2(ON THE WEBSITE YOU'RE TRYING TO LOGIN ON!)
$v1 = $_POST['acc']; // Value of field1(FROM THE WEBSITE YOU'RE TRYING TO LOGIN FROM!)
$v2 = $_POST['pw']; // Value of field2(FROM THE WEBSITE YOU'RE TRYING TO LOGIN FROM!)
$find = 'Welcome to your account'; // String to search for in the page you've logged in on
$postchars = http_build_query( array($f1 => $v1, $f2 => $v2) );

$stream = stream_context_create( array('http' => array('method' => 'POST', 'header'  => 'Content-Type: application/x-www-form-urlencoded', 'content' =>  htmlspecialchars_decode( $postchars ) ) ) ); // Creates an array of the sourcecode, and inputs the values of the field1 and field2

$content = file_get_contents($url, false, $stream); // Gets the sourcecode from the new page that is loaded after the input of the values.

$search = strpos($content, $find); // Search the sourcecode for the specific string in the variable "find"

if($search === false){
echo 'The login seems to be incorrect. Please try again, or check if you have a valid account';
} // If the string wasn't found
else {
echo 'Your account is valid!';
}  // If the string was found
 
__________________
Tanax is offline  
Reply With Quote
The Following User Says Thank You to Tanax For This Useful Post:
Shauny_B (03-02-2008)
Old 03-02-2008, 06:41 PM   #10 (permalink)
WebDev'n Beer Drnkn' Fool
 
stewart's Avatar
 
Join Date: Dec 2007
Location: Denver, CO
Posts: 59
Thanks: 2
stewart is on a distinguished road
Default

I do believe libcurl is faster than using that method Tanax..

I think... o_O lol
__________________
stewart::howe
Web Developer & Programmer
CelerMedia.Com | iAmStewart.com | CelerLabs.com
Send a message via ICQ to stewart Send a message via AIM to stewart Send a message via MSN to stewart Send a message via Yahoo to stewart
stewart is offline  
Reply With Quote
Old 03-03-2008, 11:07 AM   #11 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Actually, curl is harder. Curl is more lines, harder to read, and it isn't a standard(as I know it anyways..), so streams would be the ultimate way..
__________________
Tanax is offline  
Reply With Quote
Old 03-03-2008, 12:34 PM   #12 (permalink)
WebDev'n Beer Drnkn' Fool
 
stewart's Avatar
 
Join Date: Dec 2007
Location: Denver, CO
Posts: 59
Thanks: 2
stewart is on a distinguished road
Default

All true, but I do believe it is faster ?

Eventhough it is harder/longer..
__________________
stewart::howe
Web Developer & Programmer
CelerMedia.Com | iAmStewart.com | CelerLabs.com
Send a message via ICQ to stewart Send a message via AIM to stewart Send a message via MSN to stewart Send a message via Yahoo to stewart
stewart is offline  
Reply With Quote
Old 03-03-2008, 12:36 PM   #13 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Perhaps, but not noticible
__________________
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:37 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design