Learning & Integrating web technology and code help directory

How to use PHP & Cookies ($_COOKIE,$HTTP_COOKIE_VARS)

No comments
How to use PHP & Cookies  ($_COOKIE,$HTTP_COOKIE_VARS) Learn PHP how to using Cookies and read a php variable , Create Cookies , Read Cookies , Delete/Clear Cookies
ShotDev Focus:
- Create Cookies
- Read Cookies
- Delete/Clear Cookies
Example
php_cookie1.php (Create Cookies)
  1. <?  
  2. ob_start();  
  3. $strName = "Mr.Weerachai Nukitra";  
  4. setcookie("strName",$strName,time()+3600); // Create Cookies Expire 1 Hour  
  5. $strSiteName = "ThaiCreate.Com";  
  6. setcookie("strSiteName",$strSiteName,time()+3600); // Create Cookies Expire 1 Hour  
  7. ?>  
  8. <html>  
  9. <head>  
  10. <title>ShotDev.Com Tutorial</title>  
  11. </head>  
  12. <body>  
  13. Cookies Created.<br><br>  
  14. <a href="php_cookie2.php">Check Cookies</a>  
  15. </body>  
  16. </html>  
  17. <?  
  18. ob_end_flush();  
  19. ?>  
php_cookie2.php (Read Cookies)
  1. <?  
  2. ob_start();  
  3. ?>  
  4. <html>  
  5. <head>  
  6. <title>ShotDev.Com Tutorial</title>  
  7. </head>  
  8. <body>  
  9. Cookies Check.<br>  
  10. $strName = <?=$_COOKIE["strName"];?><br>  
  11. $strSiteName = <?=$_COOKIE["strSiteName"];?><br>  
  12. <br>  
  13. <a href="php_cookie3.php">Delete Cookies</a>  
  14. </body>  
  15. </html>  
  16. <?  
  17. ob_end_flush();  
  18. ?>  
php_cookie3.php (Clear Cookies)
  1. <?  
  2. ob_start();  
  3. setcookie("strName"); // Delete Cookies  
  4. setcookie("strSiteName"); // Delete Cookies  
  5. ?>  
  6. <html>  
  7. <head>  
  8. <title>ShotDev.Com Tutorial</title>  
  9. </head>  
  10. <body>  
  11. Created Check.<br>  
  12. $strName = <?=$_COOKIE["strName"];?><br>  
  13. $strSiteName = <?=$_COOKIE["strSiteName"];?><br>  
  14. <br>  
  15. <a href="php_cookie1.php">Create Cookies</a><br>  
  16. <a href="php_cookie2.php">Check Cookies</a><br>  
  17. </body>  
  18. </html>  
  19. <?  
  20. ob_end_flush();  
  21. ?>  
Create a php file and save to path root-path/myphp/
Screenshot
PHP Cookie
PHP Cookie
PHP Cookie

No comments :

Post a Comment