Note that there are some explanatory texts on larger screens.

plurals
  1. POLog in with cURL and make an other request with cURL after
    text
    copied!<p>I have a problem with my requests with cURL.</p> <p>I want to log-in, it works. I want to conserve the cookie to keeep the connexion available, it works.</p> <pre><code>$lien = 'https://thewebsite.com'; $postfields = array( 'username' =&gt; 'test123', 'password' =&gt; 'test123' ); $path_cookie = 'connexion.txt'; if (!file_exists(realpath($path_cookie))) touch($path_cookie); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $lien); curl_setopt($curl, CURLOPT_COOKIESESSION, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields); curl_setopt($curl, CURLOPT_COOKIEJAR, realpath($path_cookie)); $return = curl_exec($curl); echo($return); curl_close($curl); </code></pre> <p><strong>Second part :</strong></p> <pre><code>$lien2 = 'https://thewebsite.com/myaccount'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $lien2); curl_setopt($curl, CURLOPT_COOKIESESSION, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields); curl_setopt($curl, CURLOPT_COOKIEFILE, realpath($path_cookie)); $return = curl_exec($curl); echo realpath($path_cookie); curl_close($curl); </code></pre> <p>But when I want to make an other requests, it won't work, the output is :</p> <blockquote> <p><strong>Object moved to here.</strong></p> </blockquote> <p><em>Here</em> is the page of the login (<a href="https://thewebsite.com" rel="nofollow">https://thewebsite.com</a>) ...</p> <p>So the connexion doesn't stay available and the server has been kicked out when I try to achieve the second curl command.</p> <p>Any one can help me please?</p> <p><em>Maybe the first request isn't complete before the second one, how can I make a pause between the 2 requests? (sleep won't work)</em></p>
 

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