0

さて、これは間違いなく簡単な質問であり、ばかげた質問ですが、ローカルホストで開発しているので、それが問題であることにさえ気づきませんでした。ログイン スクリプトのメンバー ページにリダイレクトするヘッダーが正しく配置されていないため、機能していません。これは wamp では問題を引き起こしませんでしたが、ライブ サーバーでは問題が発生しました。ここで説明するには長すぎる理由により、スクリプトは html ファイルに含まれています。何か問題が発生するまでスクリプトには何もエコーされませんが、その後スクリプトは停止します。リダイレクトヘッダーはどこに置くべきですか?

ログインスクリプトは次のとおりです。

<?php 

// Connects to your Database 

include ("database.php");


 //Checks if there is a login cookie

 if(isset($_SESSION['username']))


 //if there is, it logs you in and directes you to the members page

 {  
    echo '<div id="probwarn"><t1><b>You are already logged in! You do not need to do it again.</b></t1></div>';

}


 //if the login form is submitted 

 if (isset($_POST['submit'])) { // if form has been submitted

$flag = 0; // Safety net, if this gets to 1 at any point in the process, we don't upload.

 // makes sure they filled it in

if(!$_POST['username'] | !$_POST['pass']) {

    echo('<div id="probwarn"><t1>You did not fill in a required field.</t1></div>');
$flag = $flag + 1;
    }

// checks it against the database





    $pass = htmlspecialchars(mysql_real_escape_string($_POST['pass']));
    $username = htmlspecialchars(mysql_real_escape_string($_POST['username']));




   $check = mysql_query("SELECT * FROM members WHERE username = '".$username."'")or die(mysql_error());



 //Gives error if user dosen't exist

 $check2 = mysql_num_rows($check);

 if ($check2 == 0) {
if($flag == 0) {
    echo('<div id="probwarn"><t1>You must <a href="register.html">    <b>register</b></a> first.</t1></div>') ;


            }
    $flag = $flag + 1;
    }           

 $check = mysql_query("SELECT * FROM members WHERE username = '".$username."'")or     die(mysql_error());
 $pass = htmlspecialchars(mysql_real_escape_string($_POST['pass']));
    $username = htmlspecialchars(mysql_real_escape_string($_POST['username']));

 while($info = mysql_fetch_array( $check ))     

 {

 $_POST['pass'] = stripslashes($_POST['pass']);

$info['password'] = stripslashes($info['password']);

$_POST['pass'] = md5($_POST['pass']);



 //gives error if the password is wrong

if ($_POST['pass'] != $info['password']) {
 if($flag == 0) {
    echo('<div id="probwarn"><t1>Incorrect password, please try again.</t1>    </div>');
$flag ++;
     } }

   }        





 // if login is ok then we add a cookie 
 if($flag == 0) {
 $pass = htmlspecialchars(mysql_real_escape_string($_POST['pass']));
 $username = htmlspecialchars(mysql_real_escape_string($_POST['username']));



 $_SESSION['username']=$username;
 $_SESSION['password']=$pass;

 //then redirect them to the members area
//THIS IS THE HEADER 
 header("Location: ../members.html");





 } 

 } 

 else 





 // if they are not logged in 

 ?> 
 LOGIN FORM IS USUALLY HERE
4

2 に答える 2

3

exitLocation ヘッダーを設定した後、忘れていました。何をしているのか正確にわかっていない限り、常にLocation ヘッダーの後にexit(または)を付ける必要があります。die()

于 2012-06-22T16:26:04.620 に答える
0

コードのどこでも header('Location: address') を使用できますが、ヘッダーの後に exit() 関数を使用することをお勧めします。リダイレクトが実行されない場合、他のコードは実行されません。

于 2012-06-22T16:49:45.050 に答える