Learn how to pass the PHP session _php skills

Source: Internet
Author: User

The example of this article for everyone to share the PHP session three ways to transfer, for your reference, the specific content as follows

Since learning to do the next note, to solve the data sharing, do not worry about, when you have to manually set up to open cookies!

(1) Pass session_id by Get way

<?php
$sid = "Test";    Sets the ID
session_id ($SID) for a session;   The value of $sid as a session_id, easy to do test
session_start ();   Open session
$_session[' user ' = "the way of delivery";
? >
<a href= "session_3.php?sid=<?php echo session_id ();?>" >test_1.php</a>  //Will Session_ The value of the ID handles the modification of the

//php configuration file with Get arguments the effect of different configuration items
session.use_only_cookies =   //Turn off this option, which is to allow the session to be generated automatically via get
<a href= "session_3.php? phpsessid=<?php echo session_id ()?> ">test_1.php</a>
//write, you can save yourself to get the value

through the $_get. Session.use_trans_sid = 1    //Turn this option on, will automatically use session_id
<a href= "session_2.php" >test_2.php</a>  //No need to add any parameters to

==================================================
<a href= "SESSION_3.PHP<? php echo "?". Sid?> ">test_1.php</a> The setting of this is a bit forgotten anyway SID is a constant, contains the required content session information!

//session_3.php page 
session_id ($_get[' Sid '));  Accept sesssion_id;
Session_Start ();
Var_dump ($_session);    Print results look down

The result is as shown in figure:

(2) passed by hidden values in the form

The public part of the front is not changed
/is passed through the form form to pass
<form action= "" method= "post" >
  name: <input type= "text" Name= "uname ">
  <input type=" hidden "name=" Sid "Value=" <?php Echo session_id ();?> ">
  <input type=" Submit "Value=" OK >
</form>

//session_4 page
$sid = $_post[' sid '];
session_id ($SID);
Session_Start ();
Var_dump ($_session);    Print results Look, the results are the same can be achieved, no longer repeat the input result data

(3) The form of the document

The above is the entire content of this article, I hope to learn more about the way the PHP session is passed to help.

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.