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

WBOY
Freigeben: 2016-06-13 13:32:56
Original
1022 Leute haben es durchsucht

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>
Nach dem Login kopieren
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!