Home >Backend Development >PHP Tutorial >Variables in PHP Sessions

Variables in PHP Sessions

墨辰丷
墨辰丷Original
2018-05-15 16:24:361574browse

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 100db36a723c770d327fc0aef2ce13b1 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[&#39;views&#39;]=1;
?>
<html>
<body>
<?php
//retrieve session data
echo "Pageviews=". $_SESSION[&#39;views&#39;];
?>
</body>
</html>



#Destroy Session

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[&#39;views&#39;]))
unset($_SESSION[&#39;views&#39;]);
?>

Completely destroy the session by calling the

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:

33 PHP Sessions

PHP Sessions

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn