Home > Backend Development > PHP Tutorial > 【PHP cookie+function】

【PHP cookie+function】

WBOY
Release: 2016-06-23 13:24:35
Original
1065 people have browsed it

COOKIE+自定义函数!!!

实现简单的欢迎效果:

                    xx桑,这是您第n次光临哟

<form name = "msg" method = "POST" action = "">	请输入id:<input name = "con" type = "text"></input><br />	<input name = "submit" type = "submit"></input>	</form><?php	function welcome($c1){	if(! isset($_COOKIE['con'])){		setcookie('con', 0 ,time()+3600);		echo "WELCOME!";	}else{		$con = $_COOKIE['con'] + 1;		setcookie('con', $con,time()+3600);		echo $c1,"桑,这是您第",$con, "次光临哟";	}	}	welcome($_POST['con']);	function decoo($p2){setcookie('con', '', time()-1);}?>
Copy after login

注意setcookie之前不能有输出。setcookie有6个参数,第一个是必要的,第一个string表示变量名,第二个混合类型表取值,第三个int表时间戳。

注意自定义函数的参数返回方法有return和在参数前面直接加&。

然后是删除cookie的方法:

setcookie('con', $con, time()-1);
Copy after login


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template