我有一些简单的问题。1-如何更改指定点的PHP页面?例如
if($flag)
//go to 1.php
else
// go to 2.php
我替换的不是去?。.php
阿拉伯数字-
<form action="index.php" method="post">
<input type="button" name ="submit" value="comfirm">
如果我单击按钮索引.php则为执行如果有任何方法在特定条件下我想要索引.php则称为
例如,我们有两个文本字段和一个按钮用户必须填写两个文本并单击按钮直到转到下一页,但如果用户填写其中一个文本不得去,但以第二种方式索引.php不得调用。
if ($flag) {
header("Location:1.php");
exit(0);
}
else {
header("Location:2.php");
exit(0);
}
对于第二个问题,您可以使用Javascript(并非所有用户都启用了javascript,因此不能保证它有效),并检查字段的值,或者使用header
进行服务器站点检查并重定向用户,如上所述。
试试这个:
if($flag) {
//go to 1.php
header("Location: 1.php");
exit(0);
}
else {
//go to 2.php
header("Location: 2.php");
exit(0);
}
对于第二部分,您可能希望使用一些客户端脚本来仔细检查输入,并使用服务器端脚本来仔细检查它们。
我喜欢使用META刷新。
<meta http-equiv="refresh" content="3;url=somewhere.php">
3 是重定向查看器之前的数字(以秒为单位
对于form
验证,您需要使用 javascript。
<head>
<script type="text/javascript">
function validateForm()
{
// Conditions to check whether the text box is empty or not.
}
</script>
</head>
<form action="index.php" method="post">
<input type="button" name ="submit" value="comfirm" onsubmit = " return validateForm() ">
如果validateForm()
返回 true,则只有在单击按钮时它才会转到index.php
我认为这是
最好的方法,因为您不必与可能损失的 _POST 美元作斗争[]
if($flag)
require '1.php';
else
require '2.php';