当前位置: 编程技术>php
本页文章导读:
▪php中$_POST传递值的例子 php中$_POST传值的例子,大家参考下。
例1,使用 $_POST 传递值
<?php
$_POST['name'] = trim($_POST['name']);
if (strlen($_POST['name']) == 0) {
$errors[] = "姓名必填!";
}
例2,验证必填项
<?php
if (st.........
▪php查询字符串传值(字符串值、数字值)的例子 例1,在查询字符串中传递字符串值
<html>
<body>
<div align="center">
<p>Click a link to move to a new page:</p>
<a href="/blog_article/index/page/content1.html.html">Content 1</a><br />
.........
▪php实例:设置cookie值 在php中设置cookie值,很简单的例子,适合入门参考。
代码:
<?php
/**
* 接收参数、设置cookie
* by www.
*/
$user = $_POST['user'];
$color = $_POST['color'];
$self = $_SERVER['PHP_SELF'];
if( ( $user !.........
[1]php中$_POST传递值的例子
来源: 互联网 发布时间: 2013-12-24
php中$_POST传值的例子,大家参考下。
例1,使用 $_POST 传递值
<?php $_POST['name'] = trim($_POST['name']); if (strlen($_POST['name']) == 0) { $errors[] = "姓名必填!"; }
例2,验证必填项
<?php if (strlen($_POST['email']) == 0) { $errors[] = "请输入Email地址"; }
例3,检测必填项
<?php if (! strlen($_POST['flavor'])) { print '请输入您喜欢的冰淇淋口味'; } ?>
[2]php查询字符串传值(字符串值、数字值)的例子
来源: 互联网 发布时间: 2013-12-24
例1,在查询字符串中传递字符串值
<html> <body> <div align="center"> <p>Click a link to move to a new page:</p> <a href="/blog_article/index/page/content1.html.html">Content 1</a><br /> <a href="/blog_article/index/page/content2.html.html">Content 2</a><br /> <a href="/blog_article/index/page/content3.html.html">Content 3</a><br /> <?php $page = trim (urldecode (stripslashes ($_GET['page']))); if (isset ($page) && $page != ""){ if (is_file ($page)){ require_once ($page); } else { echo "<p>很抱歉,您请求的页面不存在。</p>"; } } ?> </div> </body> </html>
例2,在查询字符串中传递数值
<html> <head> <title>查询字符串传递数值-www.</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <div align="center"> <p>Click a link to change the text color of the verbiage below:</p> <a href="/blog_article/index/color/1.html">Green</a><br /> <a href="/blog_article/index/color/2.html">Red</a><br /> <a href="/blog_article/index/color/3.html">Blue</a><br /> <a href="/blog_article/index.html">重置信息</a> <?php if (isset ($_GET['color'])){ $color = intval ($_GET['color']); } else { $color = ""; } if ($color == 1){ $fontcolor = "00FF00"; } elseif ($color == 2){ $fontcolor = "FF0000"; } elseif ($color == 3){ $fontcolor = "0000FF"; } else { $fontcolor = "000000"; } ?><p >欢迎访问网站!</p><?php ?> </div> </body> </html>
[3]php实例:设置cookie值
来源: 互联网 发布时间: 2013-12-24
在php中设置cookie值,很简单的例子,适合入门参考。
代码:
<?php /** * 接收参数、设置cookie * by www. */ $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>
最新技术文章: