2011-12-03 18 views
-2
<?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中看到整個頁面,我不希望它。有沒有辦法解決。我正在考慮綁定會話,但我無法做到正確。如果有任何問題,請給我看看正確的方法嗎?如何防止在URL中顯示變量?

+0

「整個頁面」?你的意思是「整個文本」? –

+0

http://www.project.com/shafiq/ErrorPage.php?abc=The%20old%20password%20does%20not%20match%20with%20the%20one%20in%20the%20records 是的,我的意思是整個文本在上面的URL中提到的URL – shafiqsnss

回答

2

您應該urlencode($msg) (string $str),並可能在標題後添加一個exit()

編輯:嗯,你只想在你的瀏覽器URL中看到ErrorPage.php,對吧?沒有任何消息或屬性?然後,您必須使用SESSIONS(或Cookie)來存儲當前用戶的消息/位置,然後將其重定向到帶有單個消息的ErrorPage

+0

我試過了,它給了我這個在URL中; ../shafiq/ErrorPage.php?abc=The+old+password+does+not+match+with+the+one+in+the+records; 它應該是這樣的不是嗎?我的意思是代碼 $ msg =「舊密碼與記錄中的密碼不匹配」; header(「Location:ErrorPage.php?abc =」。urlencode($ msg)); – shafiqsnss

1

擺脫錯誤頁面,並顯示您的錯誤oncite。

這裏是註冊碼

<? 
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'; 
?> 

的草圖和模板包含表單和誤差mesages

<? 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

0
header("Location:ErrorPage.php?abc=1"); 

ErrorPage.php

if(isset($_GET['abc'])=="1") 
{ 
Show Some Message 
} 
+0

與此問題是,我需要使用相同的頁面ErrorMessage.php來打印我做驗證時遇到的「不同」的消息,發送消息作爲參數。因此,它顯示在URL中的整個msg上。而且出現錯誤的情況太多了,所以爲所有人寫文章都很繁瑣,因爲在msg中發送的時間越長越好......至少我打出了......任何其他方式這,現在,我已經發布了這個新的約束? – shafiqsnss

+0

所以有什麼問題重定向到同一頁面,並給數字錯誤我的意思是頭(「位置:」。$ _ SERVER ['PHP_SELF']。「?error = 1」);對於錯誤1頭(「location:」。$ _ SERVER ['PHP_SELF']。「?error = 2」);對於錯誤2就像那樣並檢查是否(isset($ _ GET ['error'])){if($ _ GET ['error'] ==「1」){show error 1} elseif($ _ GET ['error' ] ==「2」){show error 2}} –

-1

您可以使用會話隱藏參數。這是最簡單的方法。