I wan to login using curl and I know how to post data using CURLOPT_POST.
after post i want to save session and then browse using that session can anyone help me out in it.
First I want to login, then I want to save session so that i can use it for next steps.
Curl send requests. It can catch the output, but it’s barely all.
If you want to mimick a browser session, then you have to realize as much Curl calls than you want to simulate link clicks.
Send your post to login.
Then send a new request for a given page, as you need.
You can have curl giving you back the html source of the page by including this:
Just because $html is empty doesn’t mean there was an error. You check for an error using curl_error() or curl_errno(), or you can strictly check for boolean false.
Remember, in php, an empty string, or string zero ‘0’ evaluates to false when you use the loose comparison operator == . If you don’t want that, you need to use strict comparison using either === or !==
See http://www.php.net/manual/en/types.comparisons.php
You’re also trying to get a bit too fancy with your assignments and expressions.
This
if($html = curl_exec($ch) == false)
Is the same as writing this
if (curl_exec($ch) == false) {
$html = true;
} else {
$html = false;
}
if ($html) {
...
You probably meant something like this, although theres other ways to do it.