0

I'm trying to set a cookie from a extern php in my website. I found this question, but its still unresolved Set-Cookie on Browser with Ajax Request via CORS

Basically my php looks like this.

<?php

ob_start();

setcookie("cookiename", "cookiedata", time() + 10000000, '/', false, false);

ob_end_flush();

header('Access-Control-Allow-Origin: *');  

?>

The header response is like this:

Access-Control-Allow-Orig...    *
Connection  Keep-Alive
Content-Length  0
Content-Type    text/html
Date    Wed, 01 Oct 2014 20:53:51 GMT
Keep-Alive  timeout=5, max=100
Server  Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
Set-Cookie  cookiename=cookiedata; expires=Sun, 25-Jan-2015 14:40:31 GMT; path=/
X-Powered-By    PHP/5.4.7

I can't see the cookie in the firebug tab (neither with other browser debuggers). When I console.log() all the cookies in javascript it does not appear either. So I don't know if someone can guide me through this. Thanks.

Community
  • 1
  • 1

1 Answers1

0

This works for me and prints out the cookie:

<?php

ob_start();

setcookie("cookiename", "cookiedata", time() + 10000000, '/', false, false);

ob_end_flush();

header('Access-Control-Allow-Origin: *');  

?>

All cookies: <p id="cookies"></p>

<script>
document.getElementById('cookies').innerHTML = document.cookie;
</script>

Or are you requesting the URL via AJAX and expecting to read the cookies in document.cookie run in the parent document?

Mark Watson
  • 146
  • 3
  • Mmm yeah I should have mentioned that, I'm calling the php with the jquery.form.js plugin, so I can make an ajax call with ie8-9 with php. I can't set cookies with an ajax call ? – user3892587 Oct 01 '14 at 22:04