Home > Backend Development > PHP Problem > Jump to the PHP page, why add a question mark?

Jump to the PHP page, why add a question mark?

PHPz
Release: 2023-04-24 14:41:56
Original
789 people have browsed it

In PHP web development, it is often necessary to perform page jump operations. When performing page jumps, we will add a question mark (?) and some parameters at the end of the URL address. So, why the question mark?

Here we need to understand the composition of the URL address. URL (Uniform Resource Locator, Uniform Resource Locator) is the address of a network resource. It consists of five parts: protocol name, host name (or IP address), port number, path and query string. Among them, the path and query string are separated by a question mark (?).

In PHP, we can get the parameter value after the question mark through the $_GET array. The following is an example:

// 页面跳转并传递参数
header('Location: target.php?id=1&name=John');
Copy after login

In the above code, we use PHP's header function to jump to the page, and add the parameters id and name after the URL. After the jump, we can get the parameter value through $_GET['id'] and $_GET['name'].

Why add a question mark? In fact, it acts as a separation. Using the question mark as the separator for parameters and paths in the URL brings great convenience to our subsequent processing of the URL. We can quickly obtain the information needed by the page by parsing the parameters after the question mark.

In addition to question marks, we can also use pound signs (#) to separate URLs. However, the content after the hash mark will not be sent to the server and only serves to mark the location in the client browser.

In short, when jumping to a PHP page, in order to facilitate subsequent processing of the URL, we need to add a question mark (?) and parameters after the URL.

The above is the detailed content of Jump to the PHP page, why add a question mark?. For more information, please follow other related articles on the PHP Chinese website!

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