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."' およびパスワード='".$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" ], "電話" => $row["電話"],"オンライン"=>1);
$count++;
}
for($i=0;$i<$count ;$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 ["グループ"],"電話"=>$contact[$i]["電話"]);
}
mysql_close($con);
?>
つまり何么每次 isset($_SESSION['$contact[$i]["id"]'])都判断不出来呢?
------解决方案---- ----------------
[ユーザー:root 時刻:12:01:13 パス:/home/liangdong/php]$ php dot.php 配列 ( [$b] => 1 ) [ユーザー:root 時刻:12:01:16 パス:/home/liangdong/php]$ cat dot.php <?php $a['$b'] = 1; print_r($a); ?> [ユーザー:root 時刻:12:01:18 パス:/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>