Isset () in php session problems cannot be judged

Source: Internet
Author: User
Tags php session
In php, the session problem isset () cannot judge login. php & lt ;? Phpsession_start (); include_once 'fuctions. php '; $ account =$ _ REQUEST [& quot; account & quot;]; & nbsp; $ password =$ _ REQ: The session problem isset () in php cannot be determined.
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 <$ 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 <$ count; $ I ++ ){
["Group"], "phone" => $ contact [$ I] ["phone"]);
}
Mysql_close ($ con );
?>

Why can't I judge every isset ($ _ SESSION ['$ contact [$ I] ["id?

------ Solution --------------------
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
  [User: root Time: 12: 01: 18 Path:/home/liangdong/php] $
------ Solution --------------------
Set
$ _ SESSION ['$ row ["id"]'] = true; and isset ($ _ SESSION ['$ contact [$ I] ["id"]'])
Change
$ _ SESSION ["$ row ['id']"] = true; and isset ($ _ SESSION ["$ contact [$ I] ['id']"])


The quotation marks are reversed. This IDE will prompt you.



------ Solution --------------------
If (! Isset ($ _ SESSION [$ contact [$ I] ["id"]) {
$ Contact [$ I] ["online"] = 0;
}
Remove the unlucky pair of single quotes
------ Solution --------------------
$ _ SESSION [$ row ['id'] = true;
No quotation marks are required for the key values in the array.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.