curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
should do the trick.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
I have a problem with my curl :
I connect to a page with CURL. then I redirect myself to a page that is available when you are connected. and then I would like to retrieve information on this page. But how can I do to get the html code? I have the page that is displayed, but I can't get the source code for scrap
My connexion
$data = array('hardkey'=>'obligatoire',
'login'=>'xxx',
'password'=>'xxxx',
'x'=>'41',
'y'=>'14'
);
$value = http_build_query($data) . "\n";
$url = 'https://www.mywebsite.com/login.php';
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POSTFIELDS, $value);
curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch,CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
//curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
My redirection :
$url = "https://www.mywebsite.com/porte_transferer.php";
curl_setopt ($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
with that, i see the page, but idk how recover html for scrap my information
Thank for your help
Please or to participate in this conversation.