How to visit another page after login in using curl?

hawkweb

Regular Member
Joined
Aug 18, 2009
Messages
375
Reaction score
21
Hello
I have finally found a away to login into a website but now can someone help me on a way to visit another internal page after login in?

Thanks
 
Log in using cookie file and then use it to browse pages. First generate cookiefile:

PHP:
$cookiefile = tempnam("dir_name_for_cookies", uniqid());

and in every curl request add:

PHP:
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
 
He's asking on how to reirect (internally). I think you mean that you want the page embedded. Well then just use an iframe.
 
Just use the following code:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_exec($ch);

The above code ought to represent how you login. Replace $post with your POST query that you use to login. After that, before closing the curl, do the following too.

curl_setopt($ch, CURLOPT_URL, $new_url);
curl_exec($ch);
curl_close($ch);

That shall enable you to redirect to any internal pages as LOGGED IN.
 
Back
Top