doucu5836 2018-04-01 21:39
浏览 18
已采纳

我的登录系统出了什么问题? [重复]

This question already has an answer here:

I'm trying to make a login system in PHP but it isn't working as intended. The code is supposed to generate a random integer and assaign it to a cookie named "token", then it uploads the value of the cookie to a database. If there is no token, it redirects the user to a 404 page, or if the token isn't equal to the token in the database it also redirects the user to a 404 page. But when I login, instead of setting the token in the database to the cookie's value, it sets it to 2147483647. How can I make the PHP code set the token in the database to the cookie's value?

Code:

admin.php:

include_once "connect.php";
if (!empty($_POST['user']) && !empty($_POST['pass'])) {
$user = $_POST['user'];
$pass = $_POST['pass'];
$_user = mysqli_escape_string($conn, $user);
$_pass = mysqli_escape_string($conn, $pass);
$query = "SELECT * FROM supa WHERE user='$_user' AND pass='$_pass'";
$result = mysqli_query($conn, $query);
if (mysqli_fetch_assoc($result) > 0) {
  setcookie("token", random_int(111, 8942));
  $ok = $_COOKIE['token'];
  $conn->query("INSERT INTO token (token) VALUES ('$ok')");
  echo "<script>location.href = \"panel.php\"</script>";
} else {
  echo "Wrong Cridentials";
}
}

panel.php:

include_once 'connect.php';
if (!empty($_COOKIE['token'])) {
  $token = $_COOKIE['token'];
  $query = "SELECT * FROM token WHERE token='$token'";
  $result = mysqli_query($conn, $query);
  if (mysqli_fetch_assoc($result) > 0) {

  } else {
    echo "<script>location.href = \"/\";</script>";
  }
} else {
  echo "<script>location.href = \"/\";</script>";
}
</div>
  • 写回答

2条回答 默认 最新

  • dongyongju9560 2018-04-01 21:42
    关注

    It seems that you have a type problem in your database. 2147483647 is the highest number of a 32 bits integer.

    I guess you have to change your type in your database from int to varchar or something.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行