This article mainly introduces the variable Sessions in PHP. Interested friends can refer to it. I hope it will be helpful to everyone.
Before you can store user information in a PHP session, you must first start the session.
Comments: session_start()
The function must be located before the tag:
<?php session_start(); ?> <html> <body> </body> </html>
#Storing and retrieving Session variables
The correct way to store and retrieve session variables is to use PHP$_SESSION Variable:
<?php session_start(); // store session data $_SESSION['views']=1; ?> <html> <body> <?php //retrieve session data echo "Pageviews=". $_SESSION['views']; ?> </body> </html>
If you want to delete some session data, you can use the unset() or session_destroy() function.
unset() function is used to release the specified session variable:
<?php session_start(); if(isset($_SESSION['views'])) unset($_SESSION['views']); ?>
session_destroy() function: ##
<?php session_destroy(); ?>
Comments:
session_destroy( )
The session will be reset and you will lose all stored session data.
E-mail Prevent injection
##FILTER_SANITIZE_EMAIL filter from string Remove illegal characters from email
FILTER_VALIDATE_EMAIL Filter validates the value of email address
Related recommendations:
HTMl5 storage methods sessionStorage and localStorage detailed explanation
The above is the detailed content of Variables in PHP Sessions. For more information, please follow other related articles on the PHP Chinese website!