Php session code _ PHP Tutorial

Source: Internet
Author: User
Php session code. Php session code can only be used by SID to determine whether to use cookies or sessions; jump to the page cannot be headerif (isset ($ _ POST [sub]) {includeconn. inc. php; $ sqlselectidfromusers php session code

The code only uses SID to determine whether the cookie or session is used.

 ; // The Jump page cannot be the header if (isset ($ _ POST [sub]) {include conn. inc. php; $ SQL = select id from users where name = '{$ _ POST [name]}' and password = '. md5 ($ _ POST [password]). '; $ result = $ mysqli-> query ($ SQL); // save the data if ($ result-> num_rows> 0) {$ row = $ result-> fetch_assoc (); $ _ SESSION [username] =$ _ POST [name]; $ _ SESSION [uid] =$ _ POST [uid]; $ _ SESSION [isLogin5] = 1; // jump to the echo 'script '; | r | echo location = 'index. php ?. SID. '; // SID constant: Use cookie if cookie is enabled. If cookie is not enabled, use session | r | echo 'script';} The echo username and password are incorrect.}?>

Conn. inc. php

 comm.php

 Index. php

 . $ _ SESSION [username]. Hello! This is the homepage of the website; echo session_id ().; echo your permissions are as follows:; $ SQL = select allow_1, allow_2, allow_3, allow_4 from users where id = '{$ _ SESSION [uid]}'; $ result = $ mysqli-> query ($ SQL); $ user = $ result-> fetch_assoc (); if ($ user [allow_1]) {echo 111111111111 ;} if ($ user [allow_2]) {echo 222222222222;} if ($ user [allow_3]) {echo 333333333333;} if ($ user [allow_4]) {echo 444444444444 ;}?> > Page 2> Page 3> exit

The compiling of test. php and test2.php is exactly the same as that of index. php.

  


The response code only uses SID to determine whether the cookie or session is used. // The Jump page cannot be the header if (isset ($ _ POST [sub]) {include conn. inc. php; $ SQL = select id from users...

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.