0

i am trying to send POST data to file which must create COOKIE... but it does not. can someone help me?

this is the file with cURL

<?php
print_r($_COOKIE);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost/site/test.php");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_POST,true);
curl_setopt($curl,CURLOPT_POSTFIELDS,"email=$email&name=$name");

$output = curl_exec($ch);

curl_close($ch);
?>

this is the file which must create COOKIE

<?php
setcookie("name", $_POST["name"]);
?>
BARNI
  • 162
  • 2
  • 10
  • 2
    It ends up in the `CURLOPT_COOKIEJAR`/`FILE` at best, not in the detached `$_COOKIE` array of the calling PHP script. – mario Feb 27 '15 at 22:21
  • You have to read the cookies from the curl output: http://stackoverflow.com/questions/895786/how-to-get-the-cookies-from-a-php-curl-into-a-variable – developerwjk Feb 27 '15 at 22:22

1 Answers1

1

You should enable cookies like this:

 curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
 curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
 curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
user2203703
  • 1,955
  • 4
  • 22
  • 36