0

I have this software from another programmer who has left the project. Now I have a problem, some of the URLs with GET variables wont work i think it's because of the # so this URL looks like this.

www.domain.com/myvariable1/myvariable-#2

so as you can see the GET variable only parses 'myvariable-' so the #2 is cutted off. I need to have the full 'myvariable-#2'

I have searched google and spent hours to get this resolved. Please help me. Thank you!


EDIT:

So I found a solution in doing this. I parse the whole URL using javascript, and from there I can now get the remaining string after the #

Thank you for all the answers. Thanks a lot!

3
  • 2
    ...thats not a get variable, its part of the url. Cant you break the requested url up by its components? Commented Oct 14, 2013 at 2:51
  • That's not an URL. It's missing the scheme, a mandatory part of URL.
    – Jan Hudec
    Commented Oct 14, 2013 at 7:36
  • 1
    If answers have helped you, then please select one as 'Solution'.
    – user338195
    Commented Oct 14, 2013 at 10:47

3 Answers 3

11

The # starts a fragment identifier. Fragments are handled client-side, that part of the URI isn't even sent to the server in the first place, so you simply cannot handle it there.

3
  • @MichaelT it is another programmer's software. and he left. I am hired to continue what he is doing, unfortunately this is one of his mistakes. Commented Oct 14, 2013 at 3:29
  • Jörg is right. Please read this from Alan Skorkin
    – Marcel
    Commented Oct 14, 2013 at 6:15
  • 2
    @VinmarkBenedicto: You can pass any character in URL by properly escaping it. In PHP escaping is done using urlencode. PHP will automatically decode parameter values for you, but IIRC you have to decode path yourself (using urldecode).
    – Jan Hudec
    Commented Oct 14, 2013 at 7:38
2

There is no way to get the fragment (#...) from PHP. It seems as if there is a way to do that with javascript. See Parsing URL hash/fragment identifier with JavaScript

Just in case you're on a Unix box: you can run nc (netcat) from a terminal window like this:

$ nc -l 8080

which opens a reading connection on port 8080. Now you can connect a browser on this machine to that port and request a URL, such as http://localhost:8080/foobar/baz.html#abcde. The output of netcat identifies the URL the server sees:

GET /foobar/baz.html HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.69 Safari/537.36
Accept-Encoding: gzip,deflate,sdch
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4

So the requested path is /foobar/baz.html without the fragment identifier (#abcde).

1
  • And if you're on Windows, you can examine the contents of HTTP requests using tools such as Fiddler or Charles. Commented Oct 14, 2013 at 6:39
0

As pointed out by others, in URLs # is the separator for the fragment identifier.

If a # character is included in the path, then it must be properly encoded: www.domain.com/myvariable1/myvariable-%232.

This way, the path as seen by the server will be myvariable1/myvariable-#2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.