Learning the PHP session transmission method, phpsession

Source: Internet
Author: User

Learning the PHP session transmission method, phpsession

The example in this article shares three transfer methods of PHP session for your reference. The details are as follows:

Now that you have learned how to take notes and solve data sharing, don't worry about it. When should you manually set the cookie to be opened!

(1) pass session_id through GET

<? Php $ sid = "test"; // set the idsession_id ($ sid) of a session; // the value of $ sid is treated as session_id, which is convenient for testing session_start (); // enable session $ _ SESSION ['user'] = "session transfer method";?> <A href = "session_3.php? Sid = <? Php echo session_id ();?> "> Test_1.php </a> // process the effect of modifying different configuration items in the configuration file of php by passing the session_id value through GET. use_only_cookies = // disable this option. You can use get to automatically generate a session <a href = "session_3.php? PHPSESSID = <? Php echo session_id ();?> "> Test_1.php </a> // you can save yourself from getting the value session through $ _ GET. use_trans_sid = 1 // enable this option. session_id <a href = "session_2.php"> test_2.php </a> is automatically used. // No parameter is required, ========================================================== ===========< a href = "session_3.php <? Php echo "? ". SID;?> "> Test_1.php </a> the specific setting is a bit forgotten. SID is a constant and contains the required session information! // Session_3.php page session_id ($ _ GET ['sid ']); // accept sesssion_id; session_start (); var_dump ($ _ SESSION); // view the printed result

Result

(2) Pass the Hidden values in the form

// The previous public part remains unchanged // pass the <form action = "" method = "post"> name by hiding in the form: <input type = "text" name = "uname"> <input type = "hidden" name = "sid" value = "<? Php echo session_id ();?> "> <Input type =" submit "value =" OK "> </form> // $ sid =$ _ POST ['sid'] On the session_4 page; session_id ($ sid); session_start (); var_dump ($ _ SESSION); // you can view the printed results. The results are the same and no Repeated input results are returned.

(3) File Format

The above is all the content in this article. I hope you can learn more about the transfer method of PHP session.

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.