cURL login and get page source code

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
Charmees
Forum Newbie
Posts: 2
Joined: Mon Dec 27, 2010 10:04 am

cURL login and get page source code

Post by Charmees »

well basically im trying to do that the 'subject says.
ive done my homework and had around 10 examples of using curl, but none of them worked in my case.
this is the final code i'm using

Code: Select all

<?php
$cookiefile = '/temp/cookies.txt';


#2 ways ive tried doing

#$data = array('edit[username]' => 'REMOVED', 'edit[password]' => 'REMOVED', 'edit[submit]' => 'Login');
$data = array('username] => 'REMOVED', 'password' => 'REMOVED', 'submit' => 'Login');


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://pokerrpg.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch);

curl_setopt($ch, CURLOPT_URL, 'http://pokerrpg.com/furniture_store.php');
$contents = curl_exec($ch);

echo $contents;

curl_close($ch);
?>
im not sure about the cookie file, but i just made a txt file to that location. and empty txt file. hope it's fine.

the page i'm trying is http://pokerrpg.com, you can even look the source code that both of these fields do exist.

when i run it, the output is a login page without logging in, so it does not log in. :(
Charmees
Forum Newbie
Posts: 2
Joined: Mon Dec 27, 2010 10:04 am

Re: cURL login and get page source code

Post by Charmees »

i found what was wrong, i had to use http://pokerrpg.com/login.php to send data to, not just pokerrpg.com
Post Reply