Coder Profile - Show off your skills, get a coder profile.
 
 
 
  
Posted: 2.89 Years Ago 

SPLITER
Contrib Level: 3
Total Posts: 33
I was always under the impression that PHPSESSID is a cookie generated by the session_start() function in PHP, and from what I've been told, its more secure than normal cookies in that the PHPSESSID cookie is all the $_COOKIE encoded into one cookie, leaving it impossible to be decrypted manually. Correct me if I'm wrong, but if I make a login system, and put the login name and password in $_SESSION, and if a hacker steals the victims PHPSESSID cookie, would the hacker be able to decrypt it and retrieve the login details?

Thanks in advance!
Posted: 2.89 Years Ago 

VBAssassin
United Kingdom
Contrib Level: 17
Total Posts: 5,730
Here's how a session works...

USERS BROWSER

You got the cookie on the browser... which contains an ID like: #ASDASD

That cookie saves that ID and carries it over to other pages that user visits on the SAME SITE.

That is ALL that is saved on the users computer... just an ID...

SERVER

Now... when the server gets that ID... it saves a file called ASDASD... that is where all the data saved in $_SESSION is stored. So clearly, the user can not get access to the session data   

SECURITY

What may be of more concern is a trick called "session hijacking" which is when someone steals that ID from one browser... and runs it in another browser... in effect taking over that users session... but they still will not be able to see what is in the session itself unless you do something stupid like: print_r($_SESSSION)

To help stop session hijacking you can lock a session to stuff like an IP address... so if someone accidentally posted there session id in a URL (ever seen a URL like: www.website.com/index.php?SESSIONID=dsahdjsdhslikdsdgsads)... then the IP's wont match and the session will be destroyed or the attacker issued a new ID.

You can help stop sessions being accidentally passed around by forcing session id's to be saved in cookies only via the PHP.INI file.

Kind regards,
Scott

EDIT: session_start() simply makes the connection between $_SESSION and the file on the server that the session data is saved to, and creates a session id if the user doesn't already have one.
Posted: 2.89 Years Ago 

SPLITER
Contrib Level: 3
Total Posts: 33
Okay, wow! That really helped clarify somethings. Thanks a lot for all that!
Posted: 2.88 Years Ago 

VBAssassin
United Kingdom
Contrib Level: 17
Total Posts: 5,730
No problem... just ask if you have any more questions   
Posted: 2.82 Years Ago 

SPLITER
Contrib Level: 3
Total Posts: 33
Okay, I've got another one. How would I set the expiration date/life span of the session? My session keeps expiring as I quit my browser.
Posted: 2.82 Years Ago 

VBAssassin
United Kingdom
Contrib Level: 17
Total Posts: 5,730
Post Quote - Direct Reference
Thats what sessions are supposed to do for security reasons.

Session cookies have an expire time of 0... meaning they expire when the browser is closed. Just change that setting    there is some stuff in the php.ini file to help you with it.

Kind regards,
Scott
Posted: 2.82 Years Ago 

Relish
United States
Contrib Level: 9
Total Posts: 799
Sessions are stored on the server and cookies on the users computer

And the only thing you should ever have to store in a session for a user system is the users id.
Posted: 2.82 Years Ago 

SPLITER
Contrib Level: 3
Total Posts: 33
Yeah, I understand. Ive only got the ID and the IP in the session. :D

I looked it up but there are two functions and I don't know which one I am supposed to use:
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. ini_set('session.cookie_lifetime', 2000000);
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. ini_set('session.gc_maxlifetime', 200000);
Also, I noticed this site keeps me logged in even after I quit my browser. What time would I set the session span to if never wanted the users to be logged out?
Posted: 2.82 Years Ago 

Izzmo
United States
Contrib Level: 12
Total Posts: 1,982
Post Quote - Direct Reference
I beg to differ. There are MANY things you can store in SESSION variables.. it's not unsafe. I use SESSION all the time.
Posted: 2.82 Years Ago 

VBAssassin
United Kingdom
Contrib Level: 17
Total Posts: 5,730
Post Quote - Direct Reference
Your browser could be set not to delete sessions when the browser closes.

Also, your better off using htaccess or php.ini files to set settings instead of ini_set()... you have a higher success rate.

Search around on php.net, and you will find the settings you need   

Kind regards,
Scott
Posted: 2.82 Years Ago 

Izzmo
United States
Contrib Level: 12
Total Posts: 1,982
Well, even if a browser does keep the session, the server will still delete it after a period of inactivity. The only way you can keep your session is if you accidently delete your tab or browser and reopen it quickly.
Page of 2 :: Next Page >>
 
 
Latest News About Coder Profile
Coder Profile Poll
Why do you get bored with programming?

Not enough time to do something productive
I run out of ideas
Too hard to show people my creations
Everything i do has too many errors, and it's too hard
I don't get bored!!!


please login to cast your vote
and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
3.49 Years Ago
Official Blog :: Make A Donation :: Credits :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents :: Wallpapers
Version 1.46.00
Copyright © 2007 - 2012, Scott Thompson, All Rights Reserved