Session in PHP

 

The main drawback of HTML is, It cannot send data from one page to another page. When a new page is loaded, all the value or data from previous page removed and new page loaded. So it is not helpful in today’s E-Commerce like shopping cart, online banking etc. where we need to maintain the all through all pages.
So to remove or overcome these drawbacks, PHP introduced a new concept called SESSION. Session is used to store data on the server for future use. This stored data in temporary.  When user closed the session,  close the browser or close the site, the session will get destroyed. It is widely used in E-Commerce, online banking etc.
Example: In E-Commerce website, When user logged in then the detail of the particular user is stored in a session and user can user that data entire the page while log out the data will destroyed.
For using the concept of session, We need three steps,
1) Start Session
2) Store value into the session
3) Destroy/ Unset  the session 
 
1) Create session
To start session, we need to write
Session_start();
Session_start();
?>
It should be the first line of your code before any HTML or text request. While writing this line session will get start.
 
2) Store value into the session
Now , we can store value into this session
$_SESSION[‘value’] = “discussdesk”;
Session_start();
$_SESSION[‘value’] = “discussdesk”;
?>
This says that discussdesk has stored in session called value. Now this value can be used entire the page.
 
3) Destroy/ Unset  the session 
Destroying the session or unset session is different
Destroying the session means it destroys all the session on that browser.
Session_destroy();
Session_start();
Session_destroy();
?>
Unset session means It unset the session for particular site.
Unset($_SESSION[‘value’]);
Session_start();
If(isset($_SESSION[‘value’]))
Unset($_SESSION[‘value’]);
?>

Share this Article on Social Media

All of my Scripts are ready to customized as per your requirement. Feel free to contact for script customization.

Contact me at discussdesk@gmail.com

"Note : It will be charged as per your customization requirement :)"

Get Updates, Scripts & Other Tutorials to Directly to your Email

Over 20000+ Happy Readers already subscribed. (We don't send spam email). Every email subscriber can get our latest updates and download our 100+ scripts.

Comments