Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?

前端 未结 12 2547
无人及你
无人及你 2020-11-21 04:37

Assuming a URL of:

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

PHP can read the request variables val1 using the GET array.

Is the ha

12条回答
  •  名媛妹妹
    2020-11-21 05:03

    Simple test, accessing 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 server receives the request without the #appendage - anything after the hash tag is simply an anchor lookup on the client.

    You can find the anchor name used within the URL via javascript using, as an example:

    
    

    The parse_url() function in PHP can work if you already have the needed URL string including the fragment (http://codepad.org/BDqjtXix):

    
    
    Output: fizzbuzz
    

    But I don't think PHP receives the fragment information because it's client-only.

提交回复
热议问题