PHP
Cookies in PHP
Set and get cookies. Get and set cookies in PHP
Example to set cookies values in PHP
Example to set cookies values in PHP
<?php $cookie_data = "Cookie information"; setcookie("CookieExample", $cookie_data); $cookie_data2 = "Info for second cookie"; // Set the expiration time to 10 seconds from the initialization $expiration_time = time()+10; setcookie("CookieExample2", $cookie_data2, $expiration_time ); echo "Current Time = ". time()." - Time = ". $expiration_time;
Example to get or retrieve cookies values in PHP
Get values from previously set cookies
<?php // Shows the data from the cookies and the current time // to help compare with the expiration time $cookie_data = $_COOKIE["CookieExample"]; echo "Cookie data: ". $cookie_data."<br/><br/>"; $cookie_data2 = $_COOKIE["CookieExample2"]; echo "Cookie data2: ". $cookie_data2."<br/><br/>"; echo "Expiration time: ". time();