When I browse the Internet, I see some URLs of websites using the # number to pass some characters as parameters, because the content after # (well) in the URL is not added to the HTTP request, so I studied it and shared it with you.
Url:http://xxx.com/index.php?id=1#01234abcd
You can see that the string behind this # is used as an identity, so how does PHP (in PHP) get this value?
In fact, PHP can not directly get this value! But we can do it in a flexible way. It is commonly used by JS to set this value into a cookie, and then PHP will be able to access the cookie data:
Javascript code var SS = Window.location.href.split ("#");d ocument.cookies = "ss=" +ss[1];
You can then use $_cookie[' SS ' in PHP to get this value.
<script language= "JavaScript" > var ss =location.href.split ("#"); Document.cookie= ' ss= ' +ss[1]; if (ss[1]! = "<?php echo $_cookie[' SS '];?>") {//To determine if the COOKIE is not up-to-date and not reload the page window.location.reload (); }</script> <?php Echo $_cookie[' SS '];?>
One drawback of this approach is that it is necessary to reload the cookie after it has been set, the PHP side will take effect, and the user experience of slow speed is poor.
Another common scenario is to use JS to get the parameters, based on the value of the PHP from the end of the AJAX data display.
such as url:http://xxx.com/#news
Location.hash can get the # number in the URL and the back part var mod = location.hash;if (mod = = "#news") {//ajax gets and processes the latest data $.ajax (...);} else if (mod = = "#hots") {//ajax gets and processes hot data $.ajax (...);}
The second method is more suitable for common AJAX applications, and programming is flexible and changeable.
============================================
Just started to learn to write some blog, write a bad place please forgive me, feel that learned to pay attention to the next bar ~
How to pass parameters after # (pound sign) in URL implementation