1

これは、ログイン (logging.php) ページで使用したコードです..これをどうすればよいですか?最初のアカウント/他のアカウントにログインしようとすると..ログイン ページは読み込まれますが、どのページにもリダイレクトされません。代わりに、空白のページしか表示されません..または、コードが間違っている場合は、これを置き換えるより良いコードを提供してください。返信をいただければ幸いです。:)私はプロジェクトのためにこれがひどく必要でした..

<?php

session_start();
  $username = $_POST['username'];
  $password = $_POST['password'];

if ( isset ($_POST['username']) )
{
 $connect = mysql_connect("localhost","root","") or die ("could'nt connect to db");
 mysql_select_db("tesda") or die ("cant connect");
 $sql=("SELECT * FROM login WHERE username='$username'");
 $result=mysql_query($sql);
 $row=mysql_fetch_array($result);

 if($result !=0 )
 {
    while($row=mysql_fetch_assoc($result))
    {
        $username = $row['username'];
        $password = $row['password'];
    }

if($row['name'] == $_POST['name'])
{

    if($_POST['username']=='tesda1'){
    header('Location: expi1.php');
    }
    else if($_POST['username']=='tesda2'){ 
    header('Location: expi2.php');
    }
    else if($_POST['username']=='tesda3'){ 
    header('Location: expi3.php');
    }
    else if($_POST['username']=='tesda4'){ 
    header('Location: expi4.php');
    }
    else if($_POST['username']=='tesda5'){ 
    header('Location: expi5.php');
    }
    else if($_POST['username']=='tesda6'){ 
    header('Location: expi6.php');
    }
    else if($_POST['username']=='tesda7'){ 
    header('Location: expi7.php');
    }
    else if($_SESSION['username']="$dbusername"){
    header('Location: attempt1.php');
    }
    else if($_SESSION['username']="$dbusername"){
    header('Location: attempt2.php');
    }
    else if($_SESSION['username']="$dbusername"){
    header('Location: attempt3.php');
    }
}
}
}
?>
4

1 に答える 1

0

以下のコードが機能するかどうかを確認してください。いくつかの小さな変更を加えました...

 <?php

    session_start();
      $username = $_POST['username'];
      $password = $_POST['password'];

    if ( isset ($_POST['username']) )
    {
     $connect = mysql_connect("localhost","root","") or die ("could'nt connect to db");
     mysql_select_db("tesda") or die ("cant connect");
     $sql="SELECT * FROM login WHERE username='$username' AND password='$password'";
     $result=mysql_query($sql);


     if(mysql_num_rows($result)==1)
     {

        if($_POST['username']=='tesda1'){
        header('Location: expi1.php');
        }
        else if($_POST['username']=='tesda2'){ 
        header('Location: expi2.php');
        }
        else if($_POST['username']=='tesda3'){ 
        header('Location: expi3.php');
        }
        else if($_POST['username']=='tesda4'){ 
        header('Location: expi4.php');
        }
        else if($_POST['username']=='tesda5'){ 
        header('Location: expi5.php');
        }
        else if($_POST['username']=='tesda6'){ 
        header('Location: expi6.php');
        }
        else if($_POST['username']=='tesda7'){ 
        header('Location: expi7.php');
        }

    }else{
        header('Location:wrongattempt.php');
    }
    }

?>

失敗した試行を処理し、失敗した試行の数を表示する別のファイルを作成します。

wrongAttempt.php

<?php
session_start();
$attempt = ++$_SESSION['count'];
echo 'Number of unsuccessful attempts = '.$attempt;

echo '<a href="login.php">Try again</a>';


?>

ログインページの先頭に以下の行を追加します。あなたのログインページはlogin.phpだと思います。 login.php

session start();
if(!isset($_SESSION['count']))
    $SESSION['count']=0; //initialize count session variable.
于 2012-10-11T04:11:24.847 に答える