homepage Welcome to WebmasterWorld Guest from 23.23.22.200
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Sessions and changing pages
Why does the session stop?
greenowl




msg:4274741
 5:13 pm on Mar 1, 2011 (gmt 0)

Hi folks - a newbie here, trying to get my head round PHP sessions.

I put session_start()in a script on main page of my website expecting the session to persist when the user looks at other pages of my site but this does not seem to be the case. The session appears to 'stop'.

If session cookies are enabled in php.ini i can get to the info by calling session_start() on another page and the cookie supplies the session id from the previous start up.

Is session_start a bit of a misnomer - should it be more like session_open - and should i try to the think of the session as a pseudo file that you open with session_start().

Or should it persist and i have set something incorrectly, perhaps.

I have Apache as a server on my PC and have set the site up on localhost.

Many thanks for any help.

 

Orangutang




msg:4274955
 11:05 pm on Mar 1, 2011 (gmt 0)

Hi greenowl,

I'm a newbie myself but I use sessions and relate to your post. You need to have session_start(); on all pages you want to use the session contents, ie session id.

The placement of session_start(); is important as well, I believe it should always be at the very top of the page which is where I put it but I've seen on occasion scripts that call in half way down the page.

Hope it helps.

greenowl




msg:4275186
 11:36 am on Mar 2, 2011 (gmt 0)

Thanks very much - getting the hang of it - it seems you have to pass the session_id across via the url link or a cookie to get at the same session on different pages.

Matthew1980




msg:4275203
 12:24 pm on Mar 2, 2011 (gmt 0)

Hi all,

Every single page that you need a reference handle to a $_SESSION needs the session_start() at the top, this is the way that php re instanciates that connection.

Hope that makes sense.

Cheers,
MRb

rocknbil




msg:4275373
 4:57 pm on Mar 2, 2011 (gmt 0)

Yeah it's a bit of a misnomer. :-) By definition [us2.php.net] it opens or resumes the current one based on a session identifier.

Note also is is the PHPSESSID cookie set in the browser that keeps the client connected to the session, otherwise you will have to append query strings to URL's.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved