0

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:/

Dharman
  • 30,962
  • 25
  • 85
  • 135
maryland
  • 21
  • 3
  • **[You should not switch off `CURLOPT_SSL_VERIFYHOST` or `CURLOPT_SSL_VERIFYPEER`](https://paragonie.com/blog/2017/10/certainty-automated-cacert-pem-management-for-php-software)**. It could be a security risk! [Here is how to get the certificate bundle if your server is missing one](https://stackoverflow.com/a/32095378/1839439) – Dharman Oct 02 '19 at 22:41
  • ```it doesn't get me any response from the curl request.``` did you check the error logs? and if there's nothing in the error logs, then enable CURLOPT_VERBOSE and check the VERBOSE log, what do you get? – hanshenrik Oct 05 '19 at 23:21

0 Answers0