Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to run: url from php = run from browser
    primarykey
    data
    text
    <p>How to run url from php script in the same way (exactly the same behaviour) as in browser when i run url from address bar. I mean with the same header data, cookies and additional data which browser send. How to add this data in php.</p> <p>I need this cause when I logged in, answers from this 2 cases are not the same:</p> <ol> <li>in browser I still logged in and this is correct</li> <li>from php run I am logged OUT - not correct </li> </ol> <p>I've tried <a href="http://php.net/manual/en/function.file-get-contents.php" rel="nofollow noreferrer">file_get_contents</a> nad <a href="https://stackoverflow.com/questions/12110378/call-url-by-php-and-checking-if-logged-in">curl (from here)</a> but it doesn't work properly - response is still different.</p> <p>I'm calling <code>http://127.0.0.1/check.html</code> and here is function check:</p> <pre><code>public function check(){ echo 'begin'; // $total_rows = file_get_contents('https://127.0.0.1:8443/example.html?shopId=121'); $total_rows = $this-&gt;getUrl('https://127.0.0.1:8443/example.html', '121'); print_r($total_rows); echo 'end'; } function getUrl($url, $shopId ='') { $post = 'shopId=' . $shopId; $ch = curl_init(); $cookie_string=""; foreach( $_COOKIE as $key =&gt; $value ) { $cookie_string .= "$key=$value;"; }; $cookie_string .= "JSESSIONIDSSO=66025D1CC9EF39ED7F5DB024B6026C61"; // echo $cookie_string;; $ch = curl_init(); curl_setopt($ch,CURLOPT_COOKIE, $cookie_string); // curl_setopt($ch, CURLOPT_PORT, 8443); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); // curl_setopt ($ch, CURLOPT_CAINFO, dirname(__FILE__)."/../../files/cacert.pem"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); // curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Secure Content-Type: text/html; charset=UTF-8")); // curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: 127.0.0.1:8443')); $ret = curl_exec($ch); curl_error ($ch ); curl_close($ch); return $ret; } </code></pre>
    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.
 

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