Sessions: Page 1 vs Page 2

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Sessions: Page 1 vs Page 2

Post by $var »

Hi webdevs!

I am having a hard time with sessions. I bet it's because I don't REALLY understand the intricacies of PHP sessions, but I'm trying to hack my way through.

I've got this simple 2 page system, an add to cart page (1) and a cart page (2).

Procedure:
- On page 1, submit a form and set $_SESSION['example']; through a function.
- On page 1, successfully echo $_SESSION['example'];
- On page 2, it fails to echo $_SESSION['example'];

Isn't the point of a session to set a variable that can be accessed on any page of the site within a time frame?

The only wildcard here is that I am in Drupal... not using Drupal sessions. I wouldn't think that would matter though.
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Re: Sessions: Page 1 vs Page 2

Post by oscardog »

Make sure at the top of both pages you have session_start().
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

[SOLVED] Sessions: Page 1 vs Page 2

Post by $var »

I found out that it was that the session would set and then when i had to refresh the page before I could call the variable.
It was weird, but it's fixed.

Thanks.
Post Reply