Home > Article > Backend Development > How to use the PHP variable php_self to implement intra-page jump_PHP tutorial
We may be interested in
. The in-page jump here is not equal to the jump of html bookmarks, but the PHP program changes the tail parameter of the URL. Provide different web content in the same program. Try comparing the following two URLs:
http://www.gxblk.com/pc/index.php
http://www.gxblk.com/pc/index.php? page=2
The difference between the above two URLs is that the second URL address has one more parameter (?page=2). When we actually open them, the content we get in the browser is different. , and they jump within the same page when clicked. This is achieved using the PHP variable php_self. The PHP program written by the user will generate different content according to the different tail parameters of index.php, but they all use the same web page program (index.php), so we call it "in-page" Jump", in fact, it generates another Web document.
We already know from the second URL address above that the built-in variable $php_self uses question marks to guide parameters. The specific expression format is as follows:
$php_self?Variable name = value (example: $php_sefl? id=0)
The variable name after the question mark is customized. Usually, it is named as a more readable English name (can be an abbreviation) as needed. For example, if we let the link point to a certain function block of the program to complete a deletion operation, then we can name it $del, which is reflected in the code as $php_self?del= value. If the link is clicked, the program will execute Delete operation (of course, the deletion operation code must be written separately):
Link code:
<ol class="dp-xml"> <li class="alt"><span><span>print </span></span></li> <li> <span>"</span><span class="tag"><</span><span> </span><span class="tag-name">a</span><span> </span><span class="attribute">href</span><span>="$php_self?</span><span class="attribute">del</span><span>=</span><span class="attribute-value">true</span><span>"</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>删除选定内容 </span></li> <li> <span class="tag"><</span><span> /a</span><span class="tag">></span><span>"; </span> </li> </ol>
Jump code:
<ol class="dp-xml"> <li class="alt"><span><span>if($</span><span class="attribute">del</span><span>=="true") </span></span></li> <li><span> { </span></li> <li class="alt"><span>//这里是删除代码 </span></li> <li><span>} </span></li> </ol>
The PHP variable php_self can take multiple parameters. The first parameter is guided by a question (?), and the subsequent parameters are guided by an ampersand (&). The format and examples are as follows:
[Syntax]$php_self?Variable1=value&Variable2=value&Variable3=value
[Example]$php_self?user=blackhorse&id=write&page=0
In principle, $php_self The tail parameters of should be written together, but the variables connected with the ampersand can be separated by spaces or other valid symbols (such as the + sign) - sometimes we do need to separate them, for example, to pass arv verification, the symbol & There will be some impact. The HTML code generated after separation is recognized by arv.
The PHP variable php_self is a very useful built-in variable in PHP, which is usually used for paging, performing predefined operations, etc. Each variable in the tail parameters it carries can be read using $ in php, such as the following address:
http://www.gxblk.com/pc/index.php?page=3
We will read the page number from the above address and display the content of the page like this:
$conts=echo_conts($page);
echo_conts is a self-written function, which uses For displaying the content of each page, the value of the variable $page is the key. It determines the content range that the program extracts from the library file.