php 中session有关问题 isset()不能判断

WBOY
Release: 2016-06-13 13:32:56
Original
1021 people have browsed it

php 中session问题 isset()不能判断
login.php
session_start();
include_once 'fuctions.php';
$account=$_REQUEST["account"];
  $password=$_REQUEST["password"];
  $con = connectDB();
  $query="select * from im where account='".$account."' and password='".$password."';";
  $result=mysql_query($query);
  if($row=mysql_fetch_array($result)){
  echo("true");
  $_SESSION['$row["id"]']=true;
  }
  else{
  echo("false");
  }
  mysql_close($con);
?>

contact.php
session_start();
include_once 'fuctions.php';
$con = connectDB();
$query = "select * from im";
$result = mysql_query($query);
$count = 0;
while ($row = mysql_fetch_array($result)) {
  $contact[$count] = array("id" => $row["id"], "name" => $row["name"], "group" => $row["group"], "phone" => $row["phone"],"online"=>1);
  $count++;
}
for($i=0;$i   if(!isset($_SESSION['$contact[$i]["id"]'])){
$contact[$i]["online"]=0;
}
}
foreach ($contact as $key => $array) {
  if (is_array($array)){
  foreach ($array as $key => $value) {
  echo($key."=>".$value." ");
  }
  }
}
$json=array();
for ($i = 0; $i   ["group"],"phone"=>$contact[$i]["phone"]);
}
mysql_close($con);
?>

为什么每次isset($_SESSION['$contact[$i]["id"]'])都判断不出来呢?

------解决方案--------------------

C/C++ code
[User:root Time:12:01:13 Path:/home/liangdong/php]$ php dot.php 
Array
(
    [$b] => 1
)
[User:root Time:12:01:16 Path:/home/liangdong/php]$ cat dot.php 
<?php $a['$b'] = 1;
print_r($a);
?>
[User:root Time:12:01:18 Path:/home/liangdong/php]$
<br><font color="#e78608">------解决方案--------------------</font><br>把<br>$_SESSION['$row["id"]']=true;和isset($_SESSION['$contact[$i]["id"]'])<br>改成<br>$_SESSION["$row['id']"]=true;和isset($_SESSION["$contact[$i]['id']"])<br><br><br>引号用反了,这种IDE应该会提示的吧<br><br><br>
<br><font color="#e78608">------解决方案--------------------</font><br>if(!isset($_SESSION[$contact[$i]["id"]])){<br> $contact[$i]["online"]=0;<br>}<br>去掉那对倒霉的单引号
<br><font color="#e78608">------解决方案--------------------</font><br>$_SESSION[$row['id']]=true;<br>数组内键值不用加引号<br> <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!