0

I am working on sessioning scripts however my cookies are not carrying over from page to page.

I include the session script on every page which checks the $_COOKIE['session'] cookie, and if set, keeps the session data, if not, creates a guest session and sets a cookie with a new key.

I can see in my SQL Table that the key is being created, however, if I brows to a page on sub directories, it creates a new key.

http://www.example.com <- Session ID [001]
http://www.example.com/subdir <- Session ID [002]

In the sub dir, the $_COOKIE['session'] variable is empty...

I am setting the cookies with the folling line:

setcookie("session", $SessionID, time() + 900, '/', '.example.com' );

If anyone could point me in the correct direction, that would be great.

*Note, cookie need to be accessed and set in every directory.

1
Contributor
3
Replies
4
Views
5 Years
Discussion Span
Last Post by mrclark
0

Solved my own problem by using the following:

setcookie("session", $SessionID, time() + 900, $_SERVER['DOCUMENT_ROOT'] . '/', '.example.com' );
0

I lied. That initially seemed to work, but ended up creating a new session on every page visit.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.