php - 登录脚本未执行 - Bluehost

标签 php mysql security authentication bluehost

我有以下登录脚本,当用户点击 www.msheeksproducts.com 登录表单上的提交按钮时运行该脚本。出于安全原因,我删除了数据库登录信息。

    <?php
error_reporting(E_ALL);
        $user = '***************';
        $pass = '***************';
        $host = '***************';
        $data = '***************';
$userN=$_POST['userN'];
$passW=$_POST['passW'];

mysql_connect($host, $user, $pass)or die("Could not connect");
mysql_select_db($data)or die("Database Not Found");

$query="SELECT userID FROM sec_login WHERE Username='$userN' AND Password='passW'";
$result=mysql_query($query) or die(mysql_error());

$user=mysql_num_rows($result);
if($user==1) {
    session_register("userN");
    header("location: ../index.php");
}
else {
echo("You have entered invalid login information.");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>

我的问题是,如果您登陆 security.php 页面,则不会发生任何事情。 PHP 脚本似乎根本没有被执行。我不确定是否在某个地方存在语法错误,或者是否是我的托管帐户的配置问题。服务器使用 PHP 5.2。有谁知道 Bluehost 是否存在此类问题的已知问题?如果存在编码错误,那么显然我也很想知道。我对此很陌生,所以我可能没有做对所有事情。

此外,我尝试在index.php文件中再次调用该变量,这似乎没有返回任何数据。

<?php $usr=$_SESSION['username']; 
echo "User Name Is: $usr"; ?>

提前致谢!

最佳答案

请考虑以下事项:

  • 谨防SQL注入(inject)(被mysql_real_escape_string阻止);
  • 谨防 session 固定/劫持;
  • 谨防暴力攻击;
  • 请查看http://php.net/pdo为了更好的错误处理和查询参数......

    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $user = '***************';
        $pass = '***************';
        $host = '***************';
        $data = '***************';
    
        mysql_connect($host, $user, $pass) or die("Could not connect");
        mysql_select_db($data) or die("Database Not Found");
    
        $result=mysql_query("SELECT COUNT(1) FROM sec_login WHERE Username='".mysql_real_escape_string($_POST['username'])."' AND Password='".mysql_real_escape_string($_POST['password'])."'") or die(mysql_error());
    
        if(mysql_result($result) == 1) {
            $_SESSION['username'] = $_POST['username'];
            header("location: ../index.php");
            exit;
        } else {
            $message = 'You have failed to provide valid credentials.';
        }
    } else {
        $message = '<form method="post">
                        <input type="text" name="username" value="username" />
                        <br />
                        <input type="password" name="password" value="password" />
                        <br />
                        <input type="submit" />
                    </form>';
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>Untitled Document</title>
        </head>
    
        <body>
            <?php echo $message; ?>
        </body>
    </html>
    

关于php - 登录脚本未执行 - Bluehost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10689444/

相关文章:

php - 如何使用 PHP 下载 2 个表格到 Excel 工作表

php - 需要帮助将数据写入多客户端 Web 应用程序中的文件?

javascript - Chrome 不允许向允许的域发出 Ajax 请求

ios - 防止非Apple用户访问当前正在开发的应用程序上的基本应用程序信息/开发者信息

php - 如何在 codeigniter 中更新表而不重复

php - 使用 INFORMATION_SCHEMA 作为根,错误说它不存在?

php - 关于点击按钮的 ID 的建议

mysql - 在 SQL 中插入一行并在存储过程中设置变量?

php - mysql_num_rows();和标题();给出重定向循环

amazon-web-services - 如何为 Amazon EMR 生成 trustedCertificates.pem 和 certificateChain.pem 文件?