Trying to login with curl but no luck

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hexbase
Forum Newbie
Posts: 1
Joined: Thu Aug 28, 2008 1:40 pm

Trying to login with curl but no luck

Post by hexbase »

Hi,

I've been trying a few scripts to login to a friend's site but i've no luck. For example, 2 scripts show as output the login page but it hasn't logged in.

Check this, for example. This script shows the login page as output, but hasn't logged in. Tell me what i should do:

Code: Select all

 
<?
$ch = curl_init();
 
curl_setopt($ch, CURLOPT_URL, "http://www.thesite.com/login.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
 
curl_setopt($ch, CURLOPT_POSTFIELDS, 'usuario=&pass=&&submit=Login');
 
echo curl_exec($ch);
curl_close($ch);
?>

Thanks!
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Trying to login with curl but no luck

Post by andyhoneycutt »

Are you sure that the page login.php actually post back to itself? If login.php's form is posting to say 'dologin.php' or something of that nature, your cURL script will fail.
Post Reply