How to use PHP & Cookies ($_COOKIE,$HTTP_COOKIE_VARS)
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
- Create Cookies
- Read Cookies
- Delete/Clear Cookies
Example
php_cookie1.php (Create Cookies)
- <?
- ob_start();
- $strName = "Mr.Weerachai Nukitra";
- setcookie("strName",$strName,time()+3600); // Create Cookies Expire 1 Hour
- $strSiteName = "ThaiCreate.Com";
- setcookie("strSiteName",$strSiteName,time()+3600); // Create Cookies Expire 1 Hour
- ?>
- <html>
- <head>
- <title>ShotDev.Com Tutorial</title>
- </head>
- <body>
- Cookies Created.<br><br>
- <a href="php_cookie2.php">Check Cookies</a>
- </body>
- </html>
- <?
- ob_end_flush();
- ?>
php_cookie2.php (Read Cookies)
- <?
- ob_start();
- ?>
- <html>
- <head>
- <title>ShotDev.Com Tutorial</title>
- </head>
- <body>
- Cookies Check.<br>
- $strName = <?=$_COOKIE["strName"];?><br>
- $strSiteName = <?=$_COOKIE["strSiteName"];?><br>
- <br>
- <a href="php_cookie3.php">Delete Cookies</a>
- </body>
- </html>
- <?
- ob_end_flush();
- ?>
php_cookie3.php (Clear Cookies)
- <?
- ob_start();
- setcookie("strName"); // Delete Cookies
- setcookie("strSiteName"); // Delete Cookies
- ?>
- <html>
- <head>
- <title>ShotDev.Com Tutorial</title>
- </head>
- <body>
- Created Check.<br>
- $strName = <?=$_COOKIE["strName"];?><br>
- $strSiteName = <?=$_COOKIE["strSiteName"];?><br>
- <br>
- <a href="php_cookie1.php">Create Cookies</a><br>
- <a href="php_cookie2.php">Check Cookies</a><br>
- </body>
- </html>
- <?
- ob_end_flush();
- ?>
Create a php file and save to path root-path/myphp/
Screenshot
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment