M
M
Mussi2014-10-19 15:58:56
PHP
Mussi, 2014-10-19 15:58:56

Curl, instead of cookies, the path to the file with them is passed, what am I doing wrong?

<?php
$request = '
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache';
$split = explode("\n",$request);	
  if( $ch = curl_init() ) {
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch,CURLOPT_URL,'http://localhost/viewcookie.php'); 
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_COOKIE, $_SERVER['DOCUMENT_ROOT'].'/cookie1.txt');
    curl_setopt($ch, CURLOPT_COOKIEJAR, $_SERVER['DOCUMENT_ROOT'].'/cookie1.txt');
  curl_setopt ($ch, CURLOPT_HTTPHEADER,$split ); 
  curl_setopt($ch, CURLOPT_ENCODING , 'gzip, deflate');
    curl_setopt($ch, CURLOPT_POSTFIELDS,"log=adm&pwd=123");
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (Windows; U; Windows NT 5.0; En; rv:1.8.0.2) Gecko/20070306 Firefox/1.0.0.4");
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_NOBODY,false);
    curl_setopt($ch,CURLOPT_HEADER,true);
  curl_setopt($ch, CURLINFO_HEADER_OUT, true);
  $out = curl_exec($ch);
echo "<b>".$out."</b>";
  echo curl_getinfo($ch, CURLINFO_HEADER_OUT);
?>

Here is the php code, I want to send cookies to a third-party site through curl, before receiving them, I received them in a file
curl_setopt($ch, CURLOPT_COOKIEJAR, $_SERVER['DOCUMENT_ROOT'].'/cookie1.txt');

everything is exactly registered in them,
I want to send the same cookies now (of course, all this will be a different request, but this does not change the essence of the problem)
curl_setopt($ch, CURLOPT_COOKIE, $_SERVER['DOCUMENT_ROOT'].'/cookie1.txt');

but what the hell, the output echo curl_getinfo($ch, CURLINFO_HEADER_OUT);
tells me that instead of the parsed contents of the cookie1.txt file, the path to this
Cookie file is sent stupidly: Z:/home/localhost/www/cookie1.txt
at first did not believe my eyes and checked it on the locale using an example file viewcookie.php, the path to the file is actually transmitted in cookies,
how should I be and what should I do?
ps everything revolves on denver

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
KorsaR-ZN, 2014-10-19
@KorsaR-ZN

Change the CURLOPT_COOKIE option to CURLOPT_COOKIEFILE

M
Mussi, 2014-10-19
@Mussi

Everything, went the other way, on the advice of the person above, go the way of parsing, separated the headers
parsed them and got the cookie into a variable

preg_match("/Set-Cookie:(.*?)\r\n/",  $header, $cook);
   echo $cook[1];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question