Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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


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

Thanks

like image 610
steamboy Avatar asked Apr 28 '10 23:04

steamboy


People also ask

Do I need to call session_start on every page?

It must be on every page you intend to use. The variables contained in the session—such as username and favorite color—are set with $_SESSION, a global variable. In this example, the session_start function is positioned after a non-printing comment but before any HTML.

Can PHP session work with browser cookies?

You CAN use PHP sessions without cookies, as long as the browser identity is obtained somehow and yields a unique value (and this value is passed to the PHP session layer): session ID in GET (which is the "standard" PHP way if cookies are not allowed, and the "other" way you described).

What does session_start () do in PHP?

session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie. When session_start() is called or when a session auto starts, PHP will call the open and read session save handlers.


1 Answers

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.

like image 146
Reece45 Avatar answered Nov 14 '22 22:11

Reece45