PHP Session
 
SESSION VARIABLE
 
  
 Thank u for reading this  Article hope it was useful ! -Regards ScriptsSnippets 
- A cookie recides on the users web Browser and may be suited for storing small amount of information and for limited concern on security.
- When we need to store a considerable amount of information we use session and we have a Security advantage of session being stored on the web server itself which is more secure than a Cookie on the User's Browser.
- PHP allows us to use Sessions by a Session Variable which is a 'Super Global' , It holds information about a Single User.
- Sessions create a Unique Id for each Visitor and stores variables based on this UID
SESSION START
- First we must start up a Session before using it to store User's Information
Session Start Snippet
| <?php   session_start(); ?> <html> <body> </body> </html> | 
Note:The session_start() function should be included before outputting any HTML content
SESSION VARIABLE
- A Session variable is created by the variable $_SESSION
- We can assign any name to a Session variable
      Session Variable Snippet
| <?php session_start(); // store session data $_SESSION['name’]=”sathesh”; ?> <html> <body> <?php //retrieve session data echo "The Author of ScriptsSnippets is=". $_SESSION['name']; ?> </body> </html> Output: The   Author of ScriptsSnippets is Sathesh | 
SESSION DESTROY
- If you want to unset a particular Session variable we can use the unset() function to remove the value from the session variable
| <?php unset($_SESSION['name']); ?> | 
- When you do not need any of your Session variable and our aim is to completely destroy the session then we use session_destroy() function.
| <?php session_destroy(); ?> | 
 00:24
00:24
 Sathesh
Sathesh
 

 Posted in:
 Posted in:   









 

0 comments:
Post a Comment