<?php
if(isset($_POST['chgPwd']))
{
$oldpwd=$_POST["txtOldPassword"];
$newpwd=$_POST["txtNewPassword"];
$cnewpwd=$_POST["txtConfirmNewPassword"];
//did stuff to get in the text fields
$oldpass = oci_result($new1,"OLDPASS");
if($oldpwd!=$oldpass)
{
$msg = "The old password does not match with the one in the records";
header("Location:ErrorPage.php?abc=".$msg);
}
}
?>
我的问题是,当我将页面重定向到 ErrorPage.php 时,我能够在 URL 中看到整个页面,这是我不希望看到的。这周围有没有。我正在考虑具有约束力的会议,但我无法正确处理。如果有的话,你能告诉我正确的方法吗?
你应该urlencode($msg) ( string $str )
,也许在标题后添加一个exit()
。
编辑:好吧,您只想在浏览器URL中看到ErrorPage.php
,对吗?没有任何消息或属性?然后,您必须使用会话(或 Cookie(来存储当前用户的消息/位置,然后将他重定向回带有单个消息ErrorPage
。
删除错误页面并显示错误。
这是注册码的草图
<?
include 'config.php';
if ($_SERVER['REQUEST_METHOD']=='POST') {
$err = array();
//performing all validations and raising corresponding errors
if (empty($_POST['name']) $err[] = "Username field is required";
if (empty($_POST['text']) $err[] = "Comments field is required";
if (!$err) {
// if no errors - saving data
// and then redirect:
header("Location: ".$_SERVER['PHP_SELF']);
exit;
} else {
// all field values should be escaped according to HTML standard
foreach ($_POST as $key => $val) {
$form[$key] = htmlspecialchars($val);
}
} else {
$form['name'] = $form['comments'] = '';
}
include 'form.tpl.php';
?>
模板包含表单和错误消息
<? if ($err): ?>
<? foreach($err as $e): ?>
<div class="err"><?=$e?></div>
<? endforeach ?>
<? endif ?>
<form>
<input type="text" name="name" value="<?=$form['name']?>">
<textarea name="comments"><?=$form['comments']?></textarea>
<input type="submit">
</form>
这是最常见的表单处理方式,称为POST/Redirect/GET
header("Location:ErrorPage.php?abc=1");
错误页面.php
if(isset($_GET['abc'])=="1")
{
Show Some Message
}
您可以使用会话来隐藏该参数。这是最简单的方法。