gpt4 book ai didi

php - 登录脚本不起作用(重定向)

转载 作者:太空宇宙 更新时间:2023-11-03 12:20:57 24 4
gpt4 key购买 nike

所以,我一直在尝试设置一个登录系统。我让系统正常工作,但随后我需要添加菜单按钮。出于某种奇怪的原因,这打破了它......所有的菜单都是一个简单的“ session 值是 1 吗?”问题。

这是 login.php 的主要代码:

<?php
session_start();
$errmsg='';
if($_POST['email']&&$_POST['password']){
$_SESSION['email']=$_POST['email'];
$_SESSION['password']=$_POST['password'];
header("Location: validate.php");
}
if($_SESSION['vcode']){
$code=$_SESSION['$vcode'];
if($code==4){
$errmsg="Invalid login details. Please try again.";
}else{
$errmsg='';
}
$_SESSION['vcode']==0;
}
?>

然后,它重定向到 validate.php。

<?php
session_start();
include '/home/raymonf2/mysqlincludeprs.php';
$email=$_SESSION['email'];
$pw=hash('ripemd160', $_SESSION['password']);
$status=0; // Original value is 0; not validated (yet?)
$sql = 'SELECT * FROM users WHERE username = \'' . $email . '\' AND password = \'' . $pw . '\';';

if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']. Sorry!');
}
while($row = $result->fetch_assoc()){
if($result->num_rows>0){
$status==1;
}
}

if($status==1){
// Back to homepage if okay.
unset($_SESSION['email']);
unset($_SESSION['password']);
$_SESSION['loggedin']==1;
header("Location: /index.php");
die("<a href=\"/\">Click here if not automatically redirected to index.</a>");
}else{
$_SESSION['loggedin']==0;
$_SESSION['vcode']==4;
header("Location: login.php");
}
?>

如有任何建议,我们将不胜感激。

问题是登录页面直接去验证,然后返回登录没有错误信息。

最佳答案

if($result->num_rows>0){
$status==1;//should be $status = 1;
}

也许您不需要 while 部分。

关于php - 登录脚本不起作用(重定向),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20110982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com