D
D
dura2282018-08-07 16:30:38
PHP
dura228, 2018-08-07 16:30:38

Why is the file not being created with CURLOPT_COOKIEJAR?

index.php:

<?php

$ch=curl_init("http://home.local/curlTest/cookieTest.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_COOKIE, 'curl_normal_cookie=1; curl_session_cookie=1');
curl_setopt($ch, CURLOPT_COOKIEJAR, "file.txt");
$html=curl_exec($ch);
curl_close($ch);
echo $html;

cookieTest.php:
<?php
$cook=false;
if(isset($_COOKIE['curl_session_cookie']))
{
  $cook=true;
  echo "Сессионная кука есть\r\n";
}
if(isset($_COOKIE['curl_normal_cookie']))
{
  $cook=true;
  echo "Нормальная кука есть\r\n";
}

@setcookie('curl_session_cookie', 1);
@setcookie('curl_normal_cookie', 1);

if($cook)
{
  echo "Есть куки";
}
else echo "Нет куки";

file.txt in the project folder is not created.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DimaX, 2018-09-30
@DimaX

Immediately there can be 2 options:
1) the rights to write are not set on the current folder;
and
2) the current folder for saving cookies is not at all the one you expect)) I myself have repeatedly encountered this.
Try replacing with
So that the cookie file will probably end up in the same folder as the script. Don't forget to check write permissions on this folder, of course)

I
Immortal_pony, 2015-01-16
@ykppon

SELECT SUM(inner.`red`) FROM (
    SELECT `red` FROM abtest ORDER BY id DESC LIMIT 5
) as `inner`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question