I'm trying to get the HTML response of a forum using curl. I have a PHP file that works from my pc (localhost) but when I start the script from a webspace I have - it doesn't get me any response from the curl request.
ONLY when I don't send cookies.
But I need to send cookies (which tells the external forum that I'm logged in) to see the page I want to.
That's the code:
<?php
$post_string = "";
$curl_connection = curl_init('http://external-forum.com/movies/movies.php');
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0");
curl_setopt($curl_connection, CURLOPT_COOKIE, "userid=*myuserid*; pass=*mypassword*;");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
//close the connection
curl_close($curl_connection);
echo $result;
?>
Works fine when I use the script from my pc. Does not work when I put the script on my webspace and start it from there... EXCEPT when I delete the following line:
curl_setopt($curl_connection, CURLOPT_COOKIE, "userid=*myuserid*; pass=*mypassword*;");
...then the request works from my webspace, but I can't see the page I want because the cookies which tells the forum I'm a known user (myuserid, pass) are not send. So it just shows me the loginpage as response (for example: http://external-forum.com/index.php instead of http://external-forum.com/movies/movies.php)
Am I doing something wrong with the cookies?
after error handling the output shows
"47-Maximum (20) redirects followed"
I Googled that too but didn't find a resolution yet:/