在php中设置cookie值,很简单的例子,适合入门参考。
代码:
<?php /** * 接收参数、设置cookie * by www.jb200.com */ $user = $_POST['user']; $color = $_POST['color']; $self = $_SERVER['PHP_SELF']; if( ( $user != null ) and ( $color != null ) ) { setcookie( "firstname", $user , time() + 36000 ); setcookie( "fontcolor", $color, time() + 36000 ); header( "Location:getcookie.php" ); exit(); } ?> <html> <head> <title>php 设置cookie</title> </head> <body> <form action ="<?php echo( $self ); ?>" method = "post"> 请输入您的姓名: <input type = "text" name = "user"><br><br> 请选择您喜欢的颜色:<br> <input type = "radio" name = "color" value = "#FF0000">Red <input type = "radio" name = "color" value = "#00FF00">Green <input type = "radio" name = "color" value = "#0000FF">Blue <br><br> <input type = "submit" value = "确认提交"> </form> </body> </html>