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 Answers3

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.

Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
  • @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. – Vinmark Benedicto Oct 14 '13 at 03:29
  • Jörg is right. Please read [this from Alan Skorkin](http://www.skorks.com/2010/05/what-every-developer-should-know-about-urls/) – Marcel Oct 14 '13 at 06: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 Oct 14 '13 at 07: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).

Community
  • 1
  • 1
topskip
  • 16,207
  • 15
  • 67
  • 99
  • And if you're on Windows, you can examine the contents of HTTP requests using tools such as [Fiddler](http://fiddler2.com/) or [Charles](http://www.charlesproxy.com/). – Carson63000 Oct 14 '13 at 06: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.

Erwan Legrand
  • 4,148
  • 26
  • 26