/    Sign up×
Community /Pin to ProfileBookmark

Sessions: Page 1 vs Page 2

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?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@_varauthorJun 01.2011 — The only wildcard here is that I am in Drupal... not using Drupal sessions. I wouldn't think that would matter though.
Copy linkTweet thisAlerts:
@NogDogJun 01.2011 — Did you do a session_start() on [b]both[/b] pages, before any type of output is generated on either and before any usage of $_SESSION?
×

Success!

Help @_var spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...