Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How do browsers interact with PHP programs

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how browsers interact with PHP programs". The explanation in this article is simple and clear and easy to learn and understand. please follow the editor's ideas to study and learn "how browsers interact with PHP programs".

This paper introduces the application of form in PHP program interaction.

So, what kind of interactive behavior will be caused by clicking a "button" on the browser?

(1) Interactive one, the browser sends data to apache

The browser sends data to apache in the form of a form.

The label of the form is: for example, on the following html page, pay attention to the contents of the tag:

Nickname:

Slogan:

The html page (equivalent to the overall interface), including the content in, is parsed by the browser. For example, the above html page looks like this after parsing:

As you can see, there are two text input boxes and a submit button.

If the browser only does the work of parsing the display, then there will be no apache or PHP programs. In fact, browsers often send data to apache, and the data sent is the data of tags (that is, forms).

Form data, which can be found in tags, can include buttons, drop-down menus, text input boxes, and so on. For example, the form above:

Notice that the above form also sends the PHP code file to apache. If there is no php file under the project directory (default is / Library/WebServer/Documents), you will see this prompt when you click the submit button:

So, what is the timing of sending? That is, when does the browser send form data to apache?

Triggers sending when a button of type "submit" is clicked. If there is no submit button, you need to proactively trigger the submit event of the form through js.

In addition, on the transmitted method, it is distinguished into get and post modes.

The get method, where all the information about the form appears in the requested url (you can see it on the address bar), and there is a limit to the length. For example, a get request like this:

Http://localhost/formtest.html?name=abc&slogan=hello+world

Where name and slogan are keys (key), and abc and hello world are corresponding values (value), and the data of the form is a collection of key-value pairs.

The post method, which does not display any data from the form when requested, has a weak length limit.

(2) interaction 2. PHP code accesses the contents of the form.

The form can specify that the contents of the php file in the project directory (or the current script, such as both the form and php code) be submitted to apache. After apache gets the php code, it will be handled by the PHP program, and the php code will probably need to access the contents of the form, such as login.php code, need to access the contents of the text box in the form, so how to access it?

The contents of the form (a collection of key-value pairs) are stored in the $_ GET variable (when the get method) or the $_ POST variable (when the post method), which is initialized when apache calls the PHP program.

Therefore, the PHP code can access the contents of the form by accessing the $_ GET or $_ POST variables.

For example, the code for login.php can be written as follows:

Hello, Jack!

Your slogan is:!

When you submit the form again, you can see a prompt like this on the browser:

Obviously, it's troublesome to tell whether to use $_ GET or $_ POST, so you can use the $_ REQUEST variable to access it, and $_ REQUEST works for either get or post.

It should be noted that after the PHP program parses the result, it returns the result to apache,apache, returns the html page to the browser, and finally the browser displays the result.

Thank you for reading, the above is the content of "how browsers interact with PHP programs". After the study of this article, I believe you have a deeper understanding of how browsers interact with PHP programs, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report