0

这是一个奇怪的问题

当我继续在login.php我的测试服务器上输入我的登录详细信息时,我会被重定向到admin.php我应该的页面,

但是,当我将文件上传到我的托管服务器并login.php输入我的登录详细信息时,什么都没有发生,我的意思是页面只是重新加载。我应该admin.php像在本地主机上测试我的网站时一样被重定向到页面,但在网络服务器上没有任何反应

有谁知道这是为什么?

这是我的代码:

//Open SQL connection
include 'connect.php';
//Check if user has entered Data yet
if(isset($_POST['submit']))
{   
//Get values from username and password user entered into form field
    $uname = $_POST['name'];
    $pword = $_POST['pword'];
//Get username and password from database   
    $result = mysql_query('SELECT `username`, `password` 
                            FROM player_info
                            WHERE `position` = "coach" ') or die (mysql_error());   
        while($row = mysql_fetch_array($result))
        {
            $username = $row['username'];
            $password = $row['password'];       
        }
//Check if username and password entered matched the username and password stored in the database
            if($uname != $username  || $pword != $password)
            {
            echo '<center><p style="color:red">Username and Password incorrect. Please try again</center>';
            }
                    
//if username and password match redirect to admin page         
                else if($uname = $username && $pword == $password)
                {
                            echo("<script>location.href ='admin.php'</script>");
                    session_start();
                    $_SESSION[$pword];
                    $_SESSION['username'] = $username;  
                }
            }
            echo'<ul>';
            echo'<li><a href="login.txt"><b>Source Code</a>';
            echo'</ul>';        
//Login Form    
        echo'<form name="test" action="" method="post">';
                echo'<div align="center">';
                echo '<form name="login" method="post" action="">';
                echo'<input type="text" name="name">'; echo'<input type="password" name="pword">';
                echo '<input type="submit" name="submit">';
        echo '</form>';
echo '<h2>Welcome to the Scoregasims rugby club</h2>';
echo '<img src="images/logo.jpg">';
echo'</div>';

echo'
</body>
</html>';
?>

PS我知道这段代码对sqlinjections不安全,但我还没有学习。

4

6 回答 6

1

用户标头如:

header("location:admin.php") instead of js below 
 echo("<script>location.href ='admin.php'</script>");

您还可以为此目的使用 html 重定向,如下所示:

echo "<meta http-equiv='refresh' content='0;url=admin.php'>";
于 2013-11-05T09:21:26.477 回答
0

第一:您指定了两种形式。一内一。

第二:应该正确使用标题标签。

PS:您不需要回显每个 html。您可以简单地执行以下操作。

我稍微修改了你的答案:

<?php
ob_start();
//Open SQL connection
include('connect.php');
//Check if user has entered Data yet
if(isset($_POST['submit'])){   
    //Get values from username and password user entered into form field
    $uname = $_POST['name'];
    $pword = $_POST['pword'];
    //Get username and password from database   
    $result = mysql_query('SELECT `username`, `password` FROM player_info WHERE `position` = "coach" ') or die (mysql_error());   
    while($row = mysql_fetch_array($result)){
        $username = $row['username'];
        $password = $row['password'];       
    }
    //Check if username and password entered matched the username and password stored in the database
    if($uname != $username  || $pword != $password){
    echo '<center><p style="color:red">Username and Password incorrect. Please try again</center>';
    }
    //if username and password match redirect to admin page         
    else if($uname = $username && $pword == $password){
        // echo("<script>location.href ='admin.php'</script>");
        session_start();
        $_SESSION[$pword];
        $_SESSION['username'] = $username;  
        header("Location:admin.php");
    }
}

?>
<html>
<head>
</head>
<body>
<ul>
    <li>
        <a href="login.txt"><b>Source Code</b></a>        
    </li>
</ul>      
<!-- Login Form     -->
<div align="center">
    <form name="login" method="post" action="">
        <input type="text" name="name">    
        <input type="password" name="pword">
        <input type="submit" name="submit">
    </form>
    <h2>Welcome to the Scoregasims rugby club</h2>
    <img src="images/logo.jpg">';
</div>


</body>
</html>

干杯

于 2013-11-05T09:32:17.437 回答
0

请查看以下部分:

else if($uname = $username && $pword == $password)
{
echo("<script>location.href ='admin.php'</script>");
session_start();
$_SESSION[$pword];
$_SESSION['username'] = $username;  
}

您在上面的代码中回显了重定向。如果您想在成功登录后重定向并将值保存到 session to 中admin.php,只需将此行下方的行写$_SESSION['username'] = $username;

else if($uname = $username && $pword == $password)
{        
$_SESSION[$pword];
$_SESSION['username'] = $username;  
echo("<script>location.href ='admin.php'</script>");
}

仅供参考,您必须写session_start();在脚本的顶部。

于 2013-11-05T09:26:55.973 回答
0

停止“回显”每一行 HTML - 您将不可能编写和调试 HTML。

 <?php
      some code...
      ... more code...
    ?>
      <div>Hello</div>
      <div><?php echo $user_name; ?></div>
    <?php ...more code... ?>

你的东西坏了,因为你需要在你的标签中指定脚本是什么。做<script type="text/javascript">js code here</script>

最后,不要为此回显js。只需执行以下 PHP 代码: header(Location: /admin.php);

于 2013-11-05T09:27:36.690 回答
0

您的代码中有一个错误 - else if($uname = $username && $pword == $password).. 您没有$username按照实际情况检查任何记录。我确定您打算使用 == 而不仅仅是=

于 2013-11-05T09:28:59.083 回答
0

在 else if 条件下,

 else if($uname = $username && $pword == $password)

应该像

else if($uname == $username && $pword == $password) // equal to symbol is missed

部分应该是,

   else if($uname == $username && $pword == $password)
            {
                session_start();                    
                $_SESSION['username'] = $username;  
                $_SESSION['pword'] = $pword;  
                echo ("<script>window.location.href ='admin.php';</script>");

            }
于 2013-11-05T09:49:43.200 回答