The title can be rewritten as: In a server-side application (like PHP, Ruby, Python, etc.), is it possible to read the hashed part of a URL?
P粉145543872
P粉145543872 2023-08-20 20:10:37
0
2
342

Suppose the URL is:

www.example.com/?val=1#part2

PHP can use the GET array to read the request variable val1.

Is the hash valuepart2 also readable? Or can it only be handled by the browser and JavaScript?

P粉145543872
P粉145543872

reply all (2)
P粉724256860

Simple test, visithttp://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:

If you already have a URL string containing a fragment, the parse_url() function in PHP can be used (http://codepad.org/BDqjtXix):

 输出:fizzbuzz

But I don't think PHP will receive the fragment information since it only exists on the client side.

    P粉360266095

    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 useparse_url()to parse the URL into its parts, including the fragment part, but obviously that's not your case.

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!