0

I am trying to use my Wordpress site to send a cURL request to a remote server, but when I try to do it, I get the error

Cookies are not supported by your browser

I have given 777 permissions to the cookiejar file. I have tried changing the testcookie value within the post field to be 0, with no luck. I read on another stackoverflow answer that if I include dirname(__FILE__) within the curlopt_cookiejar set function, that might fix the problem but it hasnt. Anyway here's the code to my cURL post.

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $loginUrl);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "log=$email&pwd=$password&wp-submit=Log%20In&redirect_to=$loginUrl&testcookie=1"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_COOKIESESSION, false );
    curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) .  '/uniquefilename' );
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt' );

hopefully this question isnt vague, im still a noob.

Mike
  • 23,542
  • 14
  • 76
  • 87
  • Making your site perform an HTTP request to itself is very inefficient. Could you not just include the functionality in that script to avoid an additional HTTP request? – Mike Aug 16 '18 at 19:48
  • maybe my question was confusing, but im not trying to use my site to post to itself within the script, rather a text file. – A.Gorsline Aug 16 '18 at 20:20
  • Is `$loginUrl` on the same server as the script above, or a different server? You can't send a POST request to a text file. – Mike Aug 16 '18 at 20:37
  • its on a different server. the text file is what im posting. – A.Gorsline Aug 18 '18 at 01:48
  • The question was wrong then. You are not sending a POST **to** your server, you are sending it **from** your server **to** a remote server. That's the exact opposite of how your question was worded. I edited it to what I think you are trying to do. Please correct me if I got something wrong. – Mike Aug 18 '18 at 02:01
  • What does `var_dump(file_exists(dirname(__FILE__) . '/uniquefilename'));` output? – Mike Aug 18 '18 at 02:04
  • Also, have you enabled error reporting? https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display – Mike Aug 18 '18 at 02:04
  • I'm no WP expert, but looking at the src you get this message if the `TEST_COOKIE` does not exist when you do the POST for the login. You would get this cookie by visiting the login page via GET before. But in the code you've shown you never do that and jump straight to the POST. So even if your Cookie-Jar works like this, I think you need to fill it before doing the POST. – Tobias K. Aug 18 '18 at 16:53
  • the output for the var_dump is bool(true). i have not enabled error reporting, and will do so. ok. i can definitely try that and try back Tobias K. – A.Gorsline Aug 18 '18 at 20:19

1 Answers1

0

So, I figured out what the problem was. I removed the line curl_setopt($ch, CURLOPT_COOKIESESSION, false ); and changed the value of the CURLOPT_POST to true.