views:

263

answers:

3

Hello guys,

I have a session created which is null when called from an ajax call on Safari.

header.php
session_start();
$_SESSION['test'] = 'this is my session';


mypage.php
session_start();
echo $_SESSION['test']; <-- NOT WORKING ON SAFARI

Thanks

A: 

is it null or is it ""?

when you if(isset($_SESSION['test'])) does it return true?

is this only safari? if so its your browser settings.

Is your session cookie saves sucessfully and you can read that $_session['test'] in the rest of header.php page?

do you call session_start() at the very very beginning of the page?

do you get any errors? if not - you've deffo got them turned on?

Glycerine
+2  A: 

Does it work in other browsers? Does it work in Safari without AJAX? Is this script being loaded from the same domain the original page is on?

Safari apparently has a more conservative cookie policy than other browsers. If everything on the PHP-side works, and other browsers work, I would think that Safari is not sending the session cookie back to the server.

AlReece45
This is generally the case with Safari. It has an extremely restrictive third-party cookie policy which often inteferes with sessions if you are using iframes. I'm willing to bet the Ajax call the OP is making might go to a subdomain or different domain, or has some kind of iframe involved.
zombat
I've heard Safari 4 is better, but I haven't tested it.
zombat
A: 

Add this line after the session_start() in both the files and tell me if the session id it's the same (that means that you are in the same session).

echo session_id();
Cesar