P粉7242568602023-08-21 15:01:41
Simple test, visit http://localhost:8000/hello?foo=bar#this-is-not-sent-to-server
python -c "import SimpleHTTPServer;SimpleHTTPServer.test()" Serving HTTP on 0.0.0.0 port 8000 ... localhost - - [02/Jun/2009 12:48:47] code 404, message File not found localhost - - [02/Jun/2009 12:48:47] "GET /hello?foo=bar HTTP/1.1" 404 -
The request received by the server does not contain what follows the # symbol - what follows the # symbol is just an anchor lookup on the client.
You can use javascript to find the anchor name used in the URL, for example:
<script>alert(window.location.hash);</script>
If you already have a URL string containing a fragment, the parse_url() function in PHP can be used (http://codepad.org/BDqjtXix):
<? echo parse_url("http://foo?bar#fizzbuzz",PHP_URL_FRAGMENT); ?> 输出:fizzbuzz
But I don't think PHP will receive the fragment information since it only exists on the client side.
P粉3602660952023-08-21 14:50:26
The main problem is that the browser won't even send the request with the fragment part. Fragment parts are parsed directly in the browser. Therefore, it is accessible via JavaScript.
Anyway, you can use parse_url() to parse the URL into its parts, including the fragment part, but obviously that's not your case.