Variable transfer between two web pages in php

Source: Internet
Author: User


Variable transfer between two web pages in php
[Author: bean teeth time: 22:53:08]

In website design, we often use the user login method. After login, the General website will give different pages according to different users, when a new webpage is linked to the website or a new webpage is opened, we can also see that user information can be remembered, after logging in, you can see greetings such as "XXX, Good evening" on the link or other web pages on the site. These are of course the results of variable transmission after login, during my personal homepage, I tried several variable transfer methods. Now I want to discuss them with you.
I. This is the most stupid method, and it is also the method that I initially did not come into contact with session and cookie. In this way, the variables to be passed are transmitted again in the form. For example, after a user logs in, the user sends his or her information, such as $ username and $ id, to the next webpage, of course, in many cases, if the boxes such as text and option do not want to be seen again, you can use a hidden input field. The following is an example. Assume that $ username is a variable sent to this page for authentication and verified on this page. to transfer it to the next page, you can create the file test4.php:


Create test5.php:

Open the apache server, enter http: // 127.0.0.1/test4.php, and click the button on the page. The value of $ username on the new webpage has been transferred.
Of course, the weakness of this method is obvious. It also needs to use another form and re-Send it if you want to refresh the page in test5.php. This is obviously unfriendly.


Ii. Use session. Later, I searched for some articles about the session and thought it was a very good way to pass variables. The following is an example:
Create a new file test6.php:
Session_register ("username"); // register a session variable
$ Username = "Zhang Xiaoming"; // variable value to be passed
Echo "go and see ";
?>
Create DownloadFilesa2001-12-10est7.php:
Echo "Hello, $ username, welcome! ";?> // Display the passed Variables
Note the following when using this method: It should be placed at the beginning of the file, that is" This variable can only be passed in the currently opened browser. If you want to transfer it in the newly opened window, you just need to do the following:
File: test8.php
Session_register ("username ");
$ Username = "Zhang Xiaoming ";
Echo "go and see"; // pass the id value of the current session to the next window.
?>
File DownloadFilesa2001-12-10est7.php
Echo "Hello, $ username, welcome! ";?>
3. Use cookies. The following is an example:
Create File test9.php
Echo "go and see";?>
File DownloadFilesa2001-12-10est5.php
Create test5.php:

The above is the method I drew from my webpage design and reference some articles. Here, I will introduce the transfer method rather than the introduction of session and cookie, the specific usage of the two methods has been introduced many times by other experts, so I won't be here to make an axe. If I find an error after the article is published, I will provide the correct method in the "comment" column below. Thank you for browsing.

Related content:
-Example of Using GD to output Chinese Characters in PHP
-PHP application speed-up overview
-Construct remote services using XML technology in PHP
-PHP and MySQL build powerful websites
-PHP compilation options

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.