Home > php教程 > php手册 > 演示cookie

演示cookie

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 19:38:05
Original
1713 people have browsed it

无详细内容 无 ?php/* * cookie * 浏览器所能存储的 cookie 数量是有一定限度的,因此而且每个 cookie所能写的信息也是有限的,通常是 4KB。 */ echo '$_COOKIE:'; var_dump($_COOKIE); echo 'br /'; if(! isset($_COOKIE['con'])){ setcookie('con',0,time(

<?php
/*
 * cookie
 * 浏览器所能存储的 cookie 数量是有一定限度的,因此而且每个 cookie所能写的信息也是有限的,通常是 4KB。
 */
 
 echo '$_COOKIE:';
 var_dump($_COOKIE);
 echo '<br />';
 
 
 if(! isset($_COOKIE['con'])){
 	setcookie('con',0,time()+3600); //使用 setcookie 之前不能有任何的输出信息
	echo "欢迎光临本网站!"; 	
 } else {
 	#更新cookie数据
 	$ncon = $_COOKIE['con']+1;
 	setcookie('con',$ncon,time()+3600);
 	echo "这是你第",$ncon,"次光临本网站"; 	
 }
 
 setcookie('con','',time()-1);  //设置cookie过期失效,相当于删除cookie
 
?>
Copy after login
<?php
setcookie('name','小倩');  //setcookie设置的值能在mycookie中显示
$_COOKIE['age']=18;  //该方式设置的值不能在mycookie中显示

print_r($_COOKIE);
echo '<br/>该信息来自yourcookie.php';

?>
Copy after login
<?php
/*
 * 跨页传递
 * */
print_r($_COOKIE);  //显示yourcookie.php中setcookie方式设置的值
echo '<br/>该信息来自mycookie.php';
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template