Note that there are some explanatory texts on larger screens.

plurals
  1. POCURL Doesn't Save Cookies (PHP)
    primarykey
    data
    text
    <p>I've been struggling with Logging in Wordpress for a while now with CURL (PHP). I think I have tried everything, but it seems that I've missed something. I can't get CURL to save my Cookies when I login. The weird thing, is that even though I can't save cookies to file, everything still works more or less, except Upgrading Worpdress Plugins (that is what I am working on currently). I can login to wordpress, and I can even set an automatic ugprade preg_matching the link and curling on it - Wordpress core upgrades with no problems, but for some reason when it comes to plugins - I just can't do it. I had a LOT guesses last night where the problem lies, but nothing did do. Now when I decided to compare the cookies I get from CURL and in FireFox - it turns out that there are no cookies from CURL.</p> <p>Okay, So here I set the Options (don't mind the commented stuff, I've been checking everything commenting things out and putting them in...).</p> <pre><code>$cookieFile = 'cookies.txt'; $channel = curl_init(); curl_setopt_array($channel, array ( CURLOPT_SSL_VERIFYPEER =&gt; FALSE, CURLOPT_TIMEOUT =&gt; 60, CURLOPT_FOLLOWLOCATION =&gt; 1, CURLOPT_RETURNTRANSFER =&gt; 1, CURLOPT_COOKIEFILE =&gt; $cookieFile, CURLOPT_COOKIEJAR =&gt; $cookieFile, CURLOPT_AUTOREFERER =&gt; true, CURLOPT_POSTFIELDS =&gt; $loginPostData, CURLOPT_POST =&gt; 1, #CURLOPT_FRESH_CONNECT =&gt; 1 #CURLOPT_FAILONERROR =&gt; 1 )); # curl_setopt ($channel, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); # # Shorten curl_exec for our $channel # function copen($openUrl, $custom = FALSE) { global $channel;global $siteUrl; if($custom) {$siteUrl = "";} curl_setopt ($channel, CURLOPT_URL, $siteUrl.$openUrl); $result = curl_exec ($channel) or die(curl_error($channel)); echo "&lt;h3&gt; Opening: $openUrl &lt;/h3&gt;"; return $result; } </code></pre> <p>So I did a search, and tried to get the cookies, and failed with this:</p> <pre><code> preg_match('/^Set-Cookie: (.*?);/mi', $result, $m); echo(parse_url($m[1])); </code></pre> <p>I also tried echoing the $cookieFile with file_get_contents() - empty. I checked the file about 15 times now - it is a 777 writable file. I tried writing to it with file_put_contents() and succeeded, so there is error in the file location and/or permissions. I am obviously missing something, I just can't see it.</p> <p>Best Regards :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload