开发者

PHP session is null when called in other page in safari

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

heade开发者_开发百科r.php
session_start();
$_SESSION['test'] = 'this is my session';


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

Thanks


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.


I faced the same problem, session_id() kept changing every refresh, so safari wasn't storing the session id in the cookie. By manually adding:

setcookie('PHPSESSID', session_id(), 0, '/');

I got it working.


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();


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜