Home > Backend Development > PHP Tutorial > Variable transfer between web pages in PHP programming_PHP tutorial

Variable transfer between web pages in PHP programming_PHP tutorial

WBOY
Release: 2016-07-21 14:56:36
Original
1005 people have browsed it

In website design, we often use the user login method. After logging in, the general website will give different pages according to different users. Link to a new web page of the site or open a new page. When opening a new web page, we will also see that the user's information can be remembered. What is particularly common now is that after logging in, you will see greetings such as "XXX, good evening" when you link or open other web pages of the site. Of course, these are 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 now 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 didn’t have any 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: **
**

**
**
**
**
Create test5.php:**
**
Open For the apache server, enter http://127.0.0.1/test4.php and click on the button on the page. You will find that the value of $username on the new web page 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"; //The variable value to be passed**
echo "Go and see"; **
?>**
Create test7.php:**
echo "Hello, $username, welcome Your presence!";?> //Display the passed variables**
When using this method, please note: should be placed 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_register("username");**
$username="Zhang Xiaoming";**
echo "Go and see"; // Pass the current session id value to the next window. **
?>**
File test7.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 test5.php**
Create test5.php:**
< ;?echo "Hello, $username, welcome!";?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364200.htmlTechArticleIn website design, we often use the user login method. After logging in, the general website will Different users are given different pages, linking to a new one on the site...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template