会话未设置

时间:2018-04-12 12:46:37

标签: php html wordpress session

我有以下代码,但由于某种原因会话保持空白。

有人可以帮忙解决这个问题吗?

<?php

session_start();

ob_start();

$ifLogged = $_SESSION["mbse"];

if(!isset($ifLogged))
{
    $_SESSION["mbse"] = 'not logged';
}

echo '--'.$ifLogged.'--';

//Obtain Info if User Tried to Log In
$username = $_POST[username];
$password = $_POST[password];
$submit = $_POST[submit];

if(isset($submit))
{

    $_SESSION["mbse"] = $username;

    $user = get_user_by( 'login', $username );
    if ( $user && wp_check_password( $password, $user->data->user_pass, $user->ID) )
    {

        // Automatic login //
        $user = get_user_by('login', $username );

        // Redirect URL //
        if ( !is_wp_error( $user ) )
        {
            wp_clear_auth_cookie();
            wp_set_current_user ( $user->ID );
            wp_set_auth_cookie  ( $user->ID );

            echo '<meta http-equiv="refresh" content="0;URL=/landing-page" />';


            exit();
        }
        else
        { echo 'Error';}
        //Stop Here
    }
    else
    {
       echo "Username and Passcode Do Not Match";
    }
}

//Obtain Domain and Check Alias
$domain = "$_SERVER[HTTP_HOST]";
$alias = "$_SERVER[REQUEST_URI]";

//Strip the Slashes from the Alias

$alias = str_replace("/", "", $alias);

if($alias == '')
{
    $nameInput = 'text';
}
else
{
    $nameInput = 'hidden';
}


echo'

<form method="POST">
 <div class="form-group">
<input class="form-control" type="'.$nameInput.'" value="'.$alias.'" name="username" placeholder="Input Your Username" required>
</div>
<div class="form-group">
<input class="form-control" type="password" name="password" placeholder="Input Your Password"  required />
</div>
<div class="col-sm-12  submitlogin">
<input class="btn" type="submit" name="submit" value="Submit" />
</div>
</form>';

从下一页开始,当我返回此页面时,会话最初为空,并且在第一次attemtp之后显示“未记录”。事情是,随着重定向的发生,条件正在发生变化。

非常感谢帮助!

1 个答案:

答案 0 :(得分:0)

发现它,花了比它应该的更长的时间,抱歉

数组键需要用这样的引号括起来

$username = $_POST['username'];
$password = $_POST['password'];
$submit = $_POST['submit'];