gpt4 book ai didi

php - Laravel 到基本 PHP 登录集成,工作!但无法设置 session

转载 作者:行者123 更新时间:2023-11-30 21:56:40 24 4
gpt4 key购买 nike

所以我正在尝试使用基于 laravel 的登录表,这是我什至无法将其与基本的 php 哈希登录进行比较的哈希。不,你不能让 hash 看起来和 laravel 完全一样。但我使用来自 users 表的 remember_token

这是我的 Laravel View 中的代码:

<form action="http://localhost/log/index.php" method="post">
<input type="hidden" value="{{ Auth::user()->remember_token }}" name="wex">
<button type="submit" class="btn btn-default">Check</button>
</form>

如您所见,我正在尝试 POST remember_token 值,该值将在我的 http://localhost/log/index.php 上作为变量接收。

Index.php(不使用 Laravel):

<?php
include "koneksi.php";

if (isset($_POST['wex'])) {
$token = $_POST['wex'];
$query = "SELECT * FROM users WHERE remember_token = '". $token ."'" ;
$result = mysqli_query($db_link,$query);

if (mysqli_num_rows($result) != 1) {
header("Location: http://localhost/laralearn/public/login");
}

session_start();
$_SESSION['user'] = "member";
}
else{

if(!isset($_SESSION['user'])){
header("Location: http://localhost/laralearn/public/login");
}
}


?>

<html>
<head>
<title>Customer</title>
</head>
<body>

<table cellpadding="5" cellspacing="5" border="1" align="center">
<tr>
<td colspan="2">If you can see this table, you are logged in. </td>
</tr>
<tr>
<td>Username:
</td>
<td><?php

while($data = mysqli_fetch_array($result))
{
echo "$data[name]";
}


?></td>
</tr>
<tr>
<td>
Token:
</td>
<td>
<?php echo $token; ?>
</td>
</tr>

</table>
</body>
</html>

如果 remember_token 无效(有效),则变量和页面重定向,但我无法设置 session 。该页面不断重定向到 Laravel 站点。

你能告诉我我哪里做错了吗?如果您解释一下并告诉我代码应该是什么样子,那就太好了。

谢谢。

最佳答案

在 Laravel session 中使用如下:

Session::set('user', "member");

获取 session 变量:

Session::get('user');

关于php - Laravel 到基本 PHP 登录集成,工作!但无法设置 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44923049/

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