Page 1 of 1

cURL login and get page source code

Posted: Mon Dec 27, 2010 10:25 am
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. :(

Re: cURL login and get page source code

Posted: Mon Dec 27, 2010 11:02 am
by Charmees
i found what was wrong, i had to use http://pokerrpg.com/login.php to send data to, not just pokerrpg.com