PHP表单不会提交变量会话

时间:2016-04-24 18:58:19

标签: php session

所以我得到了这段代码:

<?php
define("ACCESS", true);
if(!isset($_SESSION))
  session_start();

if(!isset($MYSQL)) {
  $MYSQLI = new mysqli("localhost", "root", "", "jo97ma98no03");
  if($MYSQLI->connect_error) {
    echo "<script>setTimeout(function() { window.location.replace(\"stängt\"); }, 1000);</script>";
  }
  else
    $MYSQL = true;
}


include "/php/ip.php";
include "/php/query.php";
include "/php/vars.php";

if($lastip === Query("bans", "value", "value", "value = '$lastip'"))
  header("Location: bannad");

$chunks = explode('.', $lastip);
$blacklist = array();
if(in_array($chunks[0], $blacklist))
  header("Location: proxy");

if(isset($_POST["login"])) {
  if(empty($_POST["login_username"]))
    $error = "Du glömde att skriva ditt användarnamn.";
  elseif(empty($_POST["login_password"]))
    $error = "Du glömde att skriva ditt lösenord.";
  else {
    $login_username = stripslashes($MYSQLI->real_escape_string($_POST["login_username"]));
    $login_password = stripslashes($MYSQLI->real_escape_string(md5($_POST["login_password"])));
    if($result = $MYSQLI->query("SELECT username,password FROM users WHERE username = '$login_username' AND password = '$login_password'")) {
      $lol = $result->num_rows;
      if($lol == 1) {
        $_SESSION["user"]["name"] = $_POST["login_username"];
        $_SESSION["user"] = true;
        header("Location: hem");
      }
      else
        $error = "Användarnamnet finns inte eller så är det fel lösenord.";
      $result->close();
    }
  }
}
?>

并且它有效,就是这样,$ _SESSION [&#34;用户&#34;] [&#34;名称&#34;]不会是$ login_username或$ _POST [&#34; login_username&#34;],无法找出原因,例如,它适用于用户名=&#39; $ var&#39;和密码=&#39; ...

但是在/ hem页面,它显示为最新用户,因为我使用了echo $ userid;来自vars.php,它给了114这是最新的用户,而不是我的。

任何人都知道为什么?

1 个答案:

答案 0 :(得分:0)

$_SESSION["user"]["name"]更改为$_SESSION["username"]并且有效。