php session

to use session,you can :

session_start();  //must be on the top of file ,to check session exist
if(isset($_SESSION["count"])){
	$_SESSION["count"]+=1;
	echo "count";
}else{
	$_SESSION["count"]=1;
}
echo "you viewd the page ".$_SESSION['count'] ."time";

delete session have two ways
one is

session_destory(); //remove all session

other is :

unset($_SESSION["count"]);
You don't need to call session_start() function to start a session when a user visits your site if you can set session.auto_start variable to 1 in php.ini file.

if user ban to store cookie in his brower, you can use :
you should close cookie in chrome brower.

session_start();
if(isset($_SESSION["count"])){
	$_SESSION["count"]+=1;
	echo "count";
	if($_SESSION["count"]>10){
		// unset($_SESSION["count"]);
		session_destroy();
	}
}else{
	$_SESSION["count"]=1;
}
echo "you viewd the page ".$_SESSION['count'] ."time";
?>
<h2><?php echo "other way is".htmlspecialchars(SID);?></h2>

it will bring session message to url,and send to server.

additional:htmlspecialchars() is prevent website from xss.

posted @ 2018-11-24 14:55  cyany_blue  阅读(77)  评论(0编辑  收藏  举报