cURL login and get page source code
Posted: Mon Dec 27, 2010 10:25 am
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
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.
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);
?>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.