Help with sessions

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
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Help with sessions

Post by raghavan20 »

1. Does php session change from page to page
In asp, the sessionid doesnot change across pages until logged off or the browser is closed, wot about php?

2. Do i have to use session_start() at every page? why do I have to do this?

3. If I use session_start() to inititate a session then isnot possible to access session id using session_id();?

4. I am developing a shopping cart, if a session id keeps changing then how can I store information about the cart in the db and I prefer storing cart information in db.
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Re: Help with sessions

Post by Dale »

raghavan20 wrote:1. Does php session change from page to page
In asp, the sessionid doesnot change across pages until logged off or the browser is closed, <span style='color:blue' title='ignorance is bliss'>what</span> about php?

2. Do i have to use session_start() at every page? why do I have to do this?

3. If I use session_start() to inititate a session then isnot possible to access session id using session_id();?

4. I am developing a shopping cart, if a session id keeps changing then how can I store information about the cart in the db and I prefer storing cart information in db.
1. Nope, they stay the same, like ASP, until the browser gets closed.

2. Any page you want the session information to be used on will always require session_start() at the top.

3. erm... someone else will have to answer that.

4. The session ID will stay the same until the user closes the browser.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

thanks for your reply mate.

but I dont understand why they wanted to use session_start() everytime when i wanted to access the sessionid using session_id()
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

raghavan20 wrote:thanks for your reply mate.

but I dont understand why they wanted to use session_start() everytime when i wanted to access the sessionid using session_id()
Well you have to obviously tell the page that you want the sessional information to be started. So adding session_start() at the top of everypage seems pretty fine IMO.
Post Reply