Jump to content
xisto Community
Sign in to follow this  
feipoh

Php - Can Anyone Tell Me What "session" Actually Do?

Recommended Posts

php - can anyone tell me what "session" actually do?

 

I was looking at this page http://www.w3schools.com/php/php_sessions.asp

 

this paragraph here:

A PHP session solves this problem by allowing you to store user information on the server for later use (i.e. username, shopping items, etc). However, session information is temporary and will be deleted after the user has left the website. If you need a permanent storage you may want to store the data in a database.

 

 

Especially this part below:

 

A PHP session solves this problem by allowing you to store user information on the server for later use

Can someone kind enough to write me a simple file so that i can test it on my laptop to check it out what excatly does it means? you know like how do i store user information on the server for later use ??

 

under what circustances people wanted to use session

 

 

I know i sound dub, but i really appreciate if someone can explain to me. Thank you.

Share this post


Link to post
Share on other sites

ok so you can store in a session variable some content to use in another page of your site..for example, you can get some text in page1.php and put it in a session variable..You can later access and use it in page2.php, page3.php etc..

example of use:
page1.php:

session_start();$_SESSION['MyVar']=$mytext;page2.php//you can display that text retained in page1.phpsession_start();echo $_SESSION['MyVar'];

Good luck using sessions :)

Share this post


Link to post
Share on other sites

Session variables are similar to "cookies", except the cookie is stored on the user's computer and session variables are stored on the server. Cookies are given an expiry date which means the informatioin is available for using in the future when the user next visits the site (persistent data), but the session variables are expired once the user closes the session *unless*, as suggested, the session variables are stored in a database.There are advantages to both, but shortcoming to each as well. Cookies are persistant only if the user is connecting to your site from the same computer all the time, whereas session variables apply regardless. On the other hand, session variables (to be persistant) need the database and the coding to manage them.Hope this helps you to understand them a little better.

Share this post


Link to post
Share on other sites

Thank you you both i fully understand now, and thank you for the code :) jlhaslip.

It wasn't my fault... thank hts.

Share this post


Link to post
Share on other sites

Well if you have any PHP software running on the computer you could actually check the session files in the PHP Directory.Also only one thing is stored on the Client Side(User) i.e. the PHPSESSID (PHP Session ID) which is actually a 32 bit character code and is transmitted with the help of GET method or COOKIES.Anyone who has that PHPSESSID gets access to all you data.On the Server Side the information is stored in a temporary directory and the name of the file is the PHPSESSID itself.All the info in the file is deleted after a particular time and not when the user leaves the site.This time limit is in the PHP.ini file.Hope you get a clear info now

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.