PHP programming the fastest to understand the fourth: date form reception session cookie

  • 2020-03-31 21:20:02
  • OfStack

Example 11: date stamp, date display
 
<?php 
echo time();//Returns a series of timestamps in seconds
echo "<br>"; 
echo date("Y-m-d H:i:s",time()+8*3600);//Format time, + 8 * 3600 to China time zone time
echo "<br>"; 
$str="2010-08-24 10:26:10"; 
echo date("Y-m-d H:i:s",strtotime($str));//Strtotime converts a string to a timestamp
echo "<br>"; 
?> 

Example 12: form variable encoding and receiving
 
<?php 
echo $str=urlencode(" The first page ");//URL variable encoding, just like Google
echo "<br>".urldecode($str);//URL variable decode, I see it
echo "<br><a href=index.php?page=".$str."> The first page </a>"; 
echo "<br>"; 
if($_GET)echo " Variables received: ".$_GET['page'];//$_GET corresponds to $_POST, and PHP automatically recognizes the URL encoding and decodes it.
echo "<br>"; 
?> 

Instance 13: session usage
 
<?php 
session_start();//The session expires immediately after the browser closes, so this declaration is required to read and write the session
$_SESSION['id']=' The server ';//So that's declaration and initialization, just like array
$_SESSION['name']=' The session '; 
print_r($_SESSION);//Session registration successfully outputs an array
echo "<br>"; 
$_SESSION['id']=' Server again ';//Change a session and look at the output
unset($_SESSION['name']);//Log out of a session and look at the output
print_r($_SESSION); 
echo "<br>"; 
?> 

Example 14: cookie usage
 
<?php 
setcookie("id"," The client ");//This is the function that declares and initializes the cookie. Close the browser and it becomes invalid
setcookie("name"," The session ",time()+3600);//This expires after 1 hour
print_r($_COOKIE);//Session registration successfully outputs an array, which can also be accessed with $HTTP_COOKIE_VARS
echo "<br>"; 
setcookie("id"," Client side ");//Change a session and look at the output
unset($_COOKIE['name']);//Log out a session and print it out again. Setcookie ("name","",time()-1); That's what a lot of books say, but you can actually log out with unset
print_r($_COOKIE); 
echo "<br>"; 
?> 

Related articles: