Cookie issue in CURL (PHP) - Cookie information not attached in CURL headers -
i have code
<?php $mloginurl = "https://www.test.com/login"; $mcookiefile = dirname(__file__).'/tmpcookies/cookie'.rand().'.txt'; define('user_agent', 'mozilla/5.0 (windows nt 5.1) applewebkit/537.36 (khtml, gecko) chrome/35.0.2309.372 safari/537.36'); define('cookie_file', $mcookiefile); define('login_form_url', $mloginurl); define('login_action_url', $mloginurl); $postvalues = array( 'user[email]' => "mymail@email.com", 'user[password]' => "mypassword" ); $headers = array( "accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", "cache-control: max-age=0", "connection: keep-alive", "keep-alive: 300", "accept-charset: iso-8859-1,utf-8;q=0.7,*;q=0.7", "accept-language: en-us,en;q=0.5", "pragma: " ); $curl = curl_init(); curl_setopt($curl, curlopt_verbose, true); curl_setopt($curl, curlopt_url, login_action_url); curl_setopt($curl, curlopt_post, true); curl_setopt($curl, curlopt_postfields, http_build_query($postvalues)); curl_setopt($curl, curlopt_ssl_verifypeer,false); curl_setopt($curl, curlopt_ssl_verifyhost, false); curl_setopt($curl, curlopt_cookiejar, cookie_file); curl_setopt($curl, curlopt_cookiefile, cookie_file); curl_setopt($curl, curlopt_useragent, user_agent); curl_setopt($curl, curlopt_returntransfer, true); curl_setopt($curl, curlopt_referer, login_form_url); curl_setopt($curl, curlopt_followlocation, true); curl_setopt($curl, curlopt_httpheader,$headers) ; curl_setopt($curl, curlinfo_header_out, true); $res = curl_exec($curl); $info = curl_getinfo($curl); print_r($info['request_header']); exit; ?>
this works fine on local computer , 1 of servers , shows following output
get / http/1.1 user-agent: mozilla/5.0 (windows nt 5.1) applewebkit/537.36 (khtml, gecko) chrome/35.0.2309.372 safari/537.36 host: www.test.com referer: https://www.test.com/login cookie: _property_session=wjroweyvthnyae5zb29jvk04wgm0z3fybmhmy1zievdbc2n6d2n3umviaxlzdfnhr1dsbun4qvh6affsrjfpyktybmdnrglxng0ywwcremezcklktne1ze1lttm0euqrsg90svhrrzhvyw5rwmfqtvhbmjvcwjbtb1fsc0rrteh2rjhhsfi3ahkwa3u4n3y3czjhtzjun2zgbwrrn0nra2z6otr4ahhvvg42bvvrs3kwtexul1hmn2joz0xrd2g3vvdimc81cghlqzjjotjvc2ryajiwake0vjzqrnhtehbleflttgf4z3hpugjeb0e3nlo2s3bwmelqnnvkawhdvs0tc0pcrlozsve5bxrhqxlhwe1ibtl4ut09--67cf6e056b84b4cae4d275507f544927802eb78d accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 cache-control: max-age=0 connection: keep-alivekeep-alive: 300 accept-charset: iso-8859-1,utf-8;q=0.7,*;q=0.7 accept-language: en-us,en;q=0.5
which means cookie created , attached in headers of curl (as can see in above header print of curl.) cookie file created @ mentioned location.
but on 1 of server code not work per expectations , gives following output
post /users/sign_in? http/1.1 user-agent: mozilla/5.0 (windows nt 5.1) applewebkit/537.36 (khtml, gecko) chrome/35.0.2309.372 safari/537.36 host: www.test.com referer: https://www.test.com/login accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 cache-control: max-age=0 connection: keep-alive keep-alive: 300 accept-charset: iso-8859-1,utf-8;q=0.7,*;q=0.7 accept-language: en-us,en;q=0.5 content-length: 76 content-type: application/x-www-form-urlencoded
means cookie information not attached in headers of curl. have checked cookie file created in (problematic) server , having cookie contents still cookie contents not included in curl headers. temporary cookie directory mentioned having full rights/permissions (777) users.
php version 5.4.19 , curl version 7.19.7 on problematic server.
if can help? have tried of solutions found on internet.
thanks in advance.
$mcookiefile = dirname(__file__).'/tmpcookies/cookie'.rand().'.txt';
remove rand() ... static file
Comments
Post a Comment