使用发布数据设置会话 [英] Set Session With Post Data

查看:72
本文介绍了使用发布数据设置会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在尝试使用基于laravel的登录表,这是我什至无法将其与基本php哈希登录进行比较的哈希表.不,您不能使哈希完全像laravel.但是我使用来自users表的remember_token.

So I'm trying to use laravel-based login table, which is the hash that I can't even compare it with basic php hash login. No, you can't make hash exactly look like laravel. But I use the remember_token that is come from users table.

这是我的laravel视图中的代码:

Here is the code on my 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>

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

As you can see, I'm trying to POST remember_token value, that will received on my http://localhost/log/index.php as variable.

Index.php(请记住,这不是使用laravel):

Index.php (Keep in mind, this is not using 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");
        }
    }


?>

如果remember_token无效(正在工作),则变量和页面将重定向,但我无法设置会话.当我尝试在新标签上打开index.php时,它正在重定向,这意味着该会话未解决.

The variable and page redirect if the remember_token isn't valid (working), but I can't set the session. When I tried to open the index.php on new tab, it's redirecting which is meaning the session isn't settled.

您能告诉我我在哪里做错了吗?如果您解释一下并告诉我代码应该是什么样子,那将是很好的.

Can you tell me where am I doing something wrong? It would be nice if you explain it and tell me what the code should look like.

谢谢.

推荐答案

session_start();放在PHP标记下.必须在有任何输出之前调用它,并且为了安全起见,请在没有任何其他输出之前将其包括在内.

Put session_start(); right under the PHP tag. It must be called before there is any output and just to be on the safe side, include it before there is anything else called either.

这篇关于使用发布数据设置会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆