douxing6532 2016-08-19 03:47
浏览 47
已采纳

登录页面允许任何密码登录php

i have a problem with my code when i add this

Login.php

 <?PHP session_start();
 $_SESSION['email'] = $_POST['email']; 

?>
<?php echo '<script>window.location = "http://somepage.com/"</script>'; ?>

my login page allows any password to log in, it displays the correct email address in my home page. but when i delete the code above and type any password it will not let me log in i have to use the correct password. why would this happen? i really need the code above to work because that allows me to log in to restricted pages this is what i use in restricted pages like profile.php

resctricted pages like profile.php

<?PHP
session_start();
if(!$_SESSION['email']){
header("Location: login");
die;
}
?>

<?PHP session_start();
$_SESSION['email'] = $_POST['email']; ?>

<?php echo '<script>window.location = "http://torcdesign.com/"</script>'; ?>

<?php 
    require_once("configur.php");
    $mysqli = new mysqli(localhost, root, password, dbname);
    # check connection
    if ($mysqli->connect_errno) {
        echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
        exit();
    }
 
$email=$_POST['email']; 


$encrypt_password = $_POST['encrypt_password']; 
$encrypt_password = hash("sha512",$encrypt_password);
 
    $sql = "SELECT * from register_login WHERE  email='$email' and encrypt_password='$encrypt_password'";
    $result = $mysqli->query($sql);
    if (!$result->num_rows == 1) {
        echo "<p>Invalid username/password combination</p>";
    } else {
        echo "<p>Logged in successfully</p>";
        // do stuffs
    }

?>       

</div>
  • 写回答

1条回答 默认 最新

  • donglaohua1671 2016-08-19 03:52
    关注

    Dont set the session before you check the condition

    <?PHP session_start(); ?>
    
    <?php echo '<script>window.location = "http://torcdesign.com/"</script>'; ?>
    
    <?php 
        require_once("configur.php");
        $mysqli = new mysqli(localhost, root, password, dbname);
        # check connection
        if ($mysqli->connect_errno) {
            echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
            exit();
        }
    
    $email=$_POST['email']; 
    
    
    $encrypt_password = $_POST['encrypt_password']; 
    $encrypt_password = hash("sha512",$encrypt_password);
    
        $sql = "SELECT * from register_login WHERE  email='$email' and encrypt_password='$encrypt_password'";
        $result = $mysqli->query($sql);
        if (!$result->num_rows == 1) {
            echo "<p>Invalid username/password combination</p>";
        } else {
            $_SESSION['email'] = $email;
            echo "<p>Logged in successfully</p>";
            // do stuffs
        }
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来