Learning & Integrating web technology and code help directory

How to use PHP & Session ($_SESSION,$HTTP_SESSION_VARS)

No comments
How to use PHP & Session ($_SESSION,$HTTP_SESSION_VARS) Learn PHP how to using Session and read a php variable , Create Session , Read Session , Delete/Clear Session
ShotDev Focus:
- Create Session
- Read Session
- Delete/Clear Session
Example
php_session1.php (Create Session)
  1. <?  
  2. session_start();  
  3. $_SESSION["strName"] = "Mr.Weerachai Nukitra";  
  4. $_SESSION["strSiteName"] = "ShotDev.Com";  
  5. session_write_close();  
  6. ?>  
  7. <html>  
  8. <head>  
  9. <title>ShotDev.Com Tutorial</title>  
  10. </head>  
  11. <body>  
  12. Session Created.<br><br>  
  13. <a href="php_session2.php">Check Session</a>  
  14. </body>  
  15. </html>  
php_session2.php (Read Session)
  1. <?  
  2. session_start();  
  3. ?>  
  4. <html>  
  5. <head>  
  6. <title>ShotDev.Com Tutorial</title>  
  7. </head>  
  8. <body>  
  9. Session Check.<br>  
  10. session_id(); = <?=session_id();?><br>  
  11. $strName = <?=$_SESSION["strName"];?><br>  
  12. $strSiteName = <?=$_SESSION["strSiteName"];?><br>  
  13. <br>  
  14. <a href="php_session3.php">Delete Session.</a>  
  15. </body>  
  16. </html>  
php_session3.php (Clear Session)
  1. <?  
  2. session_start();  
  3. //unset($_SESSION["strName"]); // Delete Single Session  
  4. //unset($_SESSION["strSiteName"]); // Delete Single Sessionn  
  5. session_destroy(); // Delete All Session  
  6. ?>  
  7. <html>  
  8. <head>  
  9. <title>ShotDev.Com Tutorial</title>  
  10. </head>  
  11. <body>  
  12. Created Check.<br>  
  13. $strName = <?=$_SESSION["strName"];?><br>  
  14. $strSiteName = <?=$_SESSION["strSiteName"];?><br>  
  15. <br>  
  16. <a href="php_session1.php">Create Session</a><br>  
  17. <a href="php_session2.php">Check Session</a><br>  
  18. </body>  
  19. </html>  
Create a php file and save to path root-path/myphp/
Screenshot
PHP Session
PHP Session
PHP Session
.

No comments :

Post a Comment