1

Hi all I am using cURL for login to site and fetching some data after login. In my script I am able to get logged in but when I am displaying result it is getting both pages(e.g login and after login both in same variable). Here is my code:

$username="abcd"; 
$password="123456"; 
$url="https://www.abcd.com/login"; 
$cookie="cookie.txt";
$url2 = "https://www.abcd.com/home";

$postdata = "username=".$username."&password=".$password; 

$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/3.0.0.1"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);  // <-- add this line
curl_setopt ($ch, CURLOPT_REFERER, $url); 

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec($ch); 

//echo $result;  

// make second request

curl_setopt($ch, CURLOPT_URL, $url2);
curl_setopt($ch, CURLOPT_POST, 0);

$data = curl_exec($ch);
var_dump($data);
curl_close($ch);

On

var_dump($data) Output

I am getting both pages 1.)https://www.abcd.com/login and 2.)https://www.abcd.com/home in same variable. Can anyone help me out! Thank you.

Community
  • 1
  • 1
Akshay
  • 700
  • 9
  • 23

0 Answers0