Variable transfer between two webpages in php [author: Bean teeth add Time: 2001-5-2822: 53: 08] in website design, we often use the user login method, after logging on to a website, a general website will give different pages based on different users. a new webpage is linked to the website or a SyntaxHighlighter is opened. all ();
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