创建cookie

来源:互联网 发布:苹果移动网络快捷方式 编辑:程序博客网 时间:2024/04/28 05:12

两个cookie将用来存储用户对于文本的字体大小和颜色选择。

<?php
if(isset($_POST['submitted'])){
 setcookie('font_size',$_POST['font_size']);
 setcookie('font_color',$_POST['font_color']);
 $msg = '<p>Your settings have been entered!Click <a href = "guestbook.php">here</a>
 to see them in action.</p>';
}
?>
<html>
<head>
 <title>Customize your settings</title>
</head>
<body>
<?
if(isset($msg)){
 print $msg;
}
?>
<p>Use this form to set your preferences:</p>
<form action = "file.php" method = "post">
<select name = "font_size">
 <option value = "">Font Size</option>
 <option value = "xx-small">xx-small </option>
 <option value = "x-small">x-small</option>
</select>
<select name = "font_color">
 <option value = "">Font Color</option>
 <option value = "999">Gray</option>
 <option value = "0c0">Green</option>
</select>
<input type = "submit" name = "submit" value = "Set your preferences"/>
<input type = "hidden" name = "submitted" value ="true"/>
</form>
</body>
</html>
cookie最重要的问题是他们在向web浏览器发送任何信息之前被创建,为了实现这个目的,这些脚本位于处理cookie发送的php代码之前。

原创粉丝点击