2017-04-01 31 views
-1

最近では、パスワード回復プログラムについて深刻な問題があります。私はif(isset($_POST['pass-submit']))reset.php?recoverykey=6602f445b4736ef3363a31e05750022dにプログラミングしていました。フォームの[送信]ボタンをクリックすると、処理のために同じページに残ります(つまり、reset.php?recoverykey=6602f445b4736ef3363a31e05750022d)。しかし、変数recoverykeyが空であるため、コードが機能しないreset.phpが必要です。 header("Location: reset.php?recoverykey=$recovery_code");を使用しても、何も機能しませんでした。 [Submit]ボタンをクリックしてもどこにいても、パスワードやパスワードの確認フィールドには、プログラムに応じて同じか間違っているかどうかをチェックできます。

ここreset.php内のすべての私のコードです:

<?php 
 

 
    ob_start(); 
 
    session_start(); 
 
    include('db-config.php'); 
 

 
    if(isset($_POST['forgot-submit'])){ 
 
     $recovery_user = $_POST['forgot-email']; 
 
     $query = "SELECT * FROM RegisteredMembers WHERE userEmail='$recovery_user'"; 
 
     $output = mysql_query($query); 
 
     $count = mysql_num_rows($output); 
 
     $row = mysql_fetch_array($output); 
 
     if($count==1){ 
 
      $error = false; 
 

 
      // Mail the Recovery link 
 
      $recovery_code = md5(uniqid(rand())); 
 
      $mTo = $recovery_user; 
 
      $mFrom = 'From: '.$website_details['name'].' Team '.'<'.$website_details['email'].'>'; 
 
      $mSubject = $website_details['name']." Account recovery Mail"; 
 
       // Message 
 
       $mMsg[0] = "Hi ".$row['fname'].", \r\n"; 
 
       $mMsg[1] = "This is the password recovery email which you have requested just few minutes before. <b>(If you havn't requested, you may kindly ingnore this Email)</b>"; 
 
       $mMsg[2] = "Here's your <a href='$web_path/reset.php?recoverykey=$recovery_code'>Password Recovery Link</a>. Clicking it would allow you to change your existing password into a new one."; 
 
       $mFinMsg = $mMsg[0].$mMsg[1].$mMsg[2]; 
 
      $sendRecMail = mail($mTo , $mSubject , $mFinMsg , $mFrom); 
 

 
      // Add recovery code to Database 
 
      $mysql = "UPDATE RegisteredMembers SET RecoveryCode='$recovery_code' WHERE userEmail='$recovery_user'"; 
 
      $result = mysql_query($mysql); 
 
      if($result){ 
 
       $error = false; 
 
       $forgotEmailMsg = "Thanks, Check your Email for recovering your password."; 
 
      } else{ 
 
       echo "Looks like there's a Disturbance and Load on server. Try again later."; 
 
      } 
 
     } else if(strlen($recovery_user)==0){ 
 
      $error = true; 
 
      $forgotEmailMsg = "Please do not leave this field empty."; 
 
     } else{ 
 
      $error = true; 
 
      $forgotEmailMsg = "No such Email found in Database."; 
 
     } 
 
    } 
 

 
?> 
 
<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
     <meta name="robots" content="noindex" /> 
 
     <link rel="stylesheet" type="text/css" href="assets/scripts/css/styles.css" /> 
 
     <title>Password Recovery</title> 
 
    </head> 
 
    <body> 
 
     <form class="iqform" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" autocomplete="off"> 
 
      <h3>Password Recovery</h3> 
 
      <label><span class="text-danger"><?php echo $forgotEmailMsg; ?></span><input type="email" placeholder="Your registered Email" name="forgot-email" required /></label> 
 
      <input type="submit" value="Next" name="forgot-submit" /> 
 
     </form> 
 
    </body> 
 
</html> 
 
<?php ob_end_flush(); ?>

<?php 
 
    ob_start(); 
 
    session_start(); 
 
?> 
 
<!DOCTYPE html> 
 
      <head> 
 
       <meta name="robots" content="noindex" /> 
 
       <link rel="stylesheet" type="text/css" href="assets/scripts/css/styles.css" /> 
 
       <title>Reset Password</title> 
 
      </head> 
 
<?php 
 
    include('db-config.php'); 
 
    function show_change_pass_form(){ 
 
     ?> 
 
       <form class="iqform" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" autocomplete="off"> 
 
        <h3>Change your Password</h3> 
 
        <label><span class="text-danger"><?php echo $passError ?></span><input type="password" placeholder="New Password" name="new-pass" required /></label> 
 
        <label><span class="text-danger"><?php echo $Con_passError; ?></span><input type="password" placeholder="Confirm Password" name="confirm-new-pass" required /></label> 
 
        <input type="submit" value="Change Password" name="pass-submit" /> 
 
       </form> 
 
     <?php 
 
    } 
 
    $recovery_code = $_GET['recoverykey']; 
 
    if(empty($recovery_code)){ 
 
     echo 'Looks like you landed elsewhere.'; 
 
    } 
 
    $sql = "SELECT * FROM RegisteredMembers WHERE RecoveryCode='$recovery_code'"; 
 
    $result = mysql_query($sql); 
 
    if($result){ 
 
     $count = mysql_num_rows($result); 
 
     if($count==1){ 
 

 
      if(isset($_POST['pass-submit'])){ 
 

 
       header("Location: reset.php?recoverykey=$recovery_code"); 
 

 
       $pass = $_POST['new-pass']; 
 
       $Con_pass = $_POST['confirm-new-pass']; 
 

 
        // Confirmation 
 
         if($pass==$Con_pass){ 
 
          $sql1 = "UPDATE RegisteredMembers SET password = '$pass' WHERE RecoveryCode = '$recovery_code'"; 
 
          $output = mysql_query($sql1); 
 
          echo $output; 
 
          $error = false; 
 
          $passError = "Password successfully changed. Feel free to Log In."; 
 
         } else if(!($pass==$Con_pass)){ 
 
          $error = true; 
 
          $Con_passError = "The Password isn't matching. Be sure you remember the New Password."; 
 
         } else if(empty($pass)){ 
 
          $error = true; 
 
          $passError = "Please do not keep the password empty."; 
 
         } else if(empty($Con_pass)){ 
 
          $error = true; 
 
          $Con_passError = "Please do not keep this field empty."; 
 
         } 
 
      } 
 
      show_change_pass_form(); 
 

 
     } else if($count==0) { 
 
      echo "No such recovery code, please don't try Spamming around!"; 
 
     } 
 
    } 
 
?> 
 
<?php ob_end_flush(); ?>

ここforget.phpで私のコード(そのあまり必要ではないが、私はこれを追加しましたが)のですが、

Forget.phpは大丈夫ですが、何かを参照できるかもしれません。

+0

*** *** [MySQL_関数を使用して] ***(http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Martin

答えて

0

まあ、私はあなたがヘッダー機能を使用してユーザーをリダイレクトする必要があると思います。 reset.phpでは、フォームアクションで、あなたは交換する必要があります。

<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?> 

で:

<?php echo $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']; ?> 

PHP_SELFが唯一のスクリプト名ではなく、クエリ文字列を返しますので、あなたのページがrecoverykeyフィールドを持っていません。 URLに

のphp-mysqlの拡張子が廃止され、

また

のob_start()、はob_end_flush()とのsession_start(PHP 7から削除されているので、あなたがreset.phpに必要されていない)、mysql_ *関数を使うべきではありません

+0

'PHP_SELFはスクリプト名のみを返します'、PHP_SELFは実行中のファイルのURLで与えられた識別子を返します。したがって、安全でなく、エンドユーザが悪用する可能性があります。 'PHP_SELF'を使うべきではありません。' $ _SERVER ['SCRIPT_FILENAME'] 'のような他のより良い' $ _SERVER'値などがあります。 – Martin

+0

ちょっとナディール、本当に私のために働いてくれてありがとう。 –

-1
if(isset($_POST['submit'])){ 
     header("Location:https://www.example.com/subname/"); 
     exit; // Exit should always be called after a redirection to 
       // cease further PHP code execution. 
    } 

送信後にrediectにこのコードを使用してください。

+0

これはdidn働いた。私はリダイレクトしたくありません。私はそれがそこにとどまることを望む。 –

+1

あなたはajaxを使いたいと思っています。 –

関連する問題