无法传递会话变量

时间:2013-02-10 07:36:28

标签: php

if(isset($_POST["username"])&& isset($_POST["password"])){
include('config.php'); //this one connects to the database

$username = $_POST["username"];
$password = md5($_POST["password"]);

$sql2=mysql_query("SELECT * FROM clinic_staff WHERE username='$username' AND password='$password'");
$count2 = mysql_num_rows($sql2);

if($count2 == 1){
  while($row2 = mysql_fetch_array($sql2)){
        $id = $row2["staff_ID"];
        $position = $row2["position"];
  }
  $_SESSION["id"] = $id;
  $_SESSION["name"] = $username;
  $_SESSION["password"] = $password;
  $_SESSION["pos"] = $position;

  header("location:index.php");
  exit();
}

问题是我无法回复index.php中的用户名。我不知道它是否成功通过。在index.php我使用了echo $_SESSION["name"];

3 个答案:

答案 0 :(得分:0)

您需要查看session_start才能开始会话。示例是here

答案 1 :(得分:0)

我没有看到session_start();。您在您使用会话变量的每个页面的顶部调用该函数。 (至少我必须在我的服务器上执行此操作,有人告诉我你实际上应该能够使用没有session_start();的Session变量,但是在我删除对{{1}的调用后,所有需要会话变量的内容都停止了}})

答案 2 :(得分:0)

put session_start();在文档的开头,上面没有空格。

相关问题