Variable transfer between two web pages in php
[Author: Douya added time: 2001-5-28 22:53:08]
In website design, we often use With this method of user login, after logging in, general websites will provide different pages according to different users. When linking to a new web page of the site or opening a new web page, we will also see the user's Information can be remembered. What is particularly common nowadays is that after logging in, you will see greetings such as "XXX, good evening" when linking or opening other web pages of the site. These are of course the results of variable transmission after logging in. In the process of making my personal homepage, I have tried several methods of variable transmission, and I will write them down to discuss with you.
1. This is the stupidest method, and it was also the method I came up with when I had no contact with sessions and cookies. This method is to transfer the variables to be transferred again in the form of a form. For example, after the user logs in, his information such as $username, $id, etc. is sent to the next web page using a form. Of course, in many cases, it is If you don’t want boxes such as text and options to be seen anymore, you can use hidden input fields. The following is an example. Assume that $username is a variable sent to this page for identity verification on the previous page and verified on this page. If you want to pass it to the next page, you can create the file test4.php:
$username="张小明";?>
Create test5.php:
Open the apache server, enter http://127.0.0.1/test4.php and click on the button on the page, you will find the new web page The value of $username has been transferred.
Of course, the weakness of this method is obvious. It also uses another form, and if you want to refresh the test5.php web page, you have to resend it. This is obviously not very friendly.
2. Use session. Later, I searched for some articles about session and felt that this was a very good way to pass variables. The following is an example to illustrate:
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-10 est7.php:
echo "Hello, $username, welcome!";?> //Display the passed variables
Be careful when using this method: should Put it at the front of the file, that is, there should be nothing in front of "", including spaces. This is the reason why I debugged many times and failed to find out. "前面不应有任何内容,包括空格,这是我调试多次未成功找出的原因。
This variable can only be passed in the currently opened browser. If you want to pass it in a newly opened window, just do it as follows:
File: test8.php
session_start(); session_register("username");
$username="Zhang Xiaoming";
echo "Go and have a look"; // Pass the current session id value to the next window.
?>
File DownloadFilesa2001-12-10 est7.php
echo "Hello, $username, welcome!";?>
Three , through cookies. Let’s illustrate with an example:
Create the file test9.php
echo "Go and have a look";?>
File DownloadFilesa2001-12-10 est5.php
Create test5.php:
The above is the method I came up with when designing the webpage and referring to some articles. Here I will introduce the transmission when I focus on it. method, rather than the introduction of session and cookie. The specific use methods of the two have been introduced many times by other experts, so I will not repeat them here. If I find errors again after the article is published, I will provide correction methods in the "Comment" column below. Thank you for browsing.
Related content:
- Example of using GD to output Chinese characters in PHP
- PHP application speedup review
- Using XML technology to construct remote services in PHP
- PHP and MySQL to build powerful Website
- PHP compilation option description
http://www.bkjia.com/PHPjc/532045.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532045.htmlTechArticleVariable transfer between two web pages in php [Author: Douya Added time: 2001-5-28 22 :53:08 ] In website design, we often use the user login method. After logging in, usually...