General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 17th, 2002, 01:44 PM
beetle18 beetle18 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Victoria, TX
Posts: 29 beetle18 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to beetle18 Send a message via AIM to beetle18
Question Best way to handle sessions?

Hey everyone

I'm new (read: 3 weeks in) with PHP and want to get a good grasp on session handling. I've read quite a bit in the PHP manual and found several tutorials...and they are all helpful, but at the same time confusing. Which is the best way? Or is it pertinent to the application?

I need sessions for the purposes of validating users based on a login to a section of a site...therefore I'd like to have most of my session handling code in an include. Right now, the setup I have works ok, and in plain language works like this:

• User logs in at index.php
• index.php submits username and password to login.php
• login.php verifies user against DB
• If user valid, session is started and registered (using an array, $mysession)
• $mysession contains username, password, realname, id, and SID.
• $SID is stuffed into a cookie ($HTTP_COOKIE_VARS['SID'])
• login.php reroutes valid users to list.php
• list.php AND all other pages 'behind the login' reference the include authorize.php
• authorize.php first checks the SID in the session versus the SID in the cookie
• If valid, then authorize.php validates the user data in the session against the DB.
• If valid, the page is displayed.
• When a user logs out, the cookie is deleted and the session destroyed.

Ok, whew. Now, what I'm confused on, is this. What is the difference between session variables I make manually ($mysession) and the global $HTTP_SESSION_VARS? And, if I'm using a flag to determine that the user is logged in (to prevent multiple logins), how do I reset that flag to 0 when the broswer is closed?

What's the difference between $PHPSESSID and $SID?

Ok, just a few more bits before I split. I'm currently on PHP 4.0.6, Red Hat 7.2, MySQL 3.23.51, Apache 1.3.22. However, we will be upgrading to PHP 4.2 later, and turing register_globals off so I will be using $_COOKIE or $_SESSION etc...

Thanks A TON!

Reply With Quote
  #2  
Old July 17th, 2002, 03:41 PM
DavidM DavidM is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 78 DavidM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
What is SID? Is side the result of calling session_id()?

I have been placing with sessions today myself and many of the questions you ask are the same questions have.

You may want to check out http://www.devshed.com -- they have some PHP articles out there called "Vault" or something that is a document management system that requires login.

The article is pretty straight forward and should give you some insight on how they did it.

Reply With Quote
  #3  
Old July 17th, 2002, 11:58 PM
beetle18 beetle18 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Victoria, TX
Posts: 29 beetle18 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to beetle18 Send a message via AIM to beetle18
Well, I'd like some clarification on SID as well. I know that if you want to pass the session ID you can append it to a header call
PHP Code:
 header("Location:page.php".SID); 
The result of doing this is one of two things:
1) if cookies are enabled, the session ID will be stored there ($HTTP_COOKIE_VARS['PHPSESSID'], or $_COOKIE['PHPSESSID'])
2) if cookies are disabled, it will show up in the URL as a GET variable (http://www.blah.com/page.php?PHPSESSID=SID string

I've also read on php.net that when you use the superglobal $_SESSION variable, then some of the session handling functions in PHP become unecessary (such as session_register()) Thus the basis of my confusion.

Note: Although adding .SID to the URL in the header makes it store as PHPSESSID, I have successfully tested and retrieved a value for $SID

Reply With Quote
  #4  
Old July 22nd, 2002, 08:32 PM
beetle18 beetle18 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Victoria, TX
Posts: 29 beetle18 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to beetle18 Send a message via AIM to beetle18
Still looking for help on this one

Lots of pagesviews to this thread but only one reply? Help/advice anyone?

My server will be switing to PHP 4.1+ soon...

Thanks!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Best way to handle sessions?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway