Forum Moderators: coopster

Message Too Old, No Replies

how to extract parameter from URL using PHP

         

Tastatura

11:11 pm on May 5, 2007 (gmt 0)

10+ Year Member



Hi all,
I am having trouble extracting parameter from URL (after page loads)

Looking at:
http://example.com?a=123&b=456&c=789#111

I am trying to get vale for "c" and everything behind it, ie c=789#111 .

$_SERVER['QUERY_STRING']
or

$HTTP_SERVER_VARS["QUERY_STRING"]

produces everything but #111 (and I really want that part as well)

Any help is greatly appriciated

Dinkar

6:13 am on May 6, 2007 (gmt 0)

10+ Year Member



The # thing is for browser. So I don't think that it's possible.

Why don't you use some other character?

phparion

7:07 am on May 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



not sure if it is a dirty way to do it however it will work, i guess

$arr = explode("#",$_SERVER['REQUEST_URI']);

print_r($arr); //$arr[1] will be the value after hash sign

also you might want to print

print_r($_SERVER); this will show you at least one option that you can use to get the complete posted URL.

jatar_k

1:18 pm on May 6, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



take a look at parse_url
[php.net...]

Tastatura

6:13 pm on May 8, 2007 (gmt 0)

10+ Year Member



Hi guys,
thanks for the info. I still can't get it to work (to capture data after # sign). I am guessing that most of my troubles are not being able to get *complete* URI of the current page (i.e. php code trying to determine URI, including data after #, on the page it is executed on).
I'll play with it some more but thanks anyways

jd01

9:22 pm on May 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am guessing that most of my troubles are not being able to get *complete* URI of the current page.

No, actually, the problem is you are *only* getting the complete URI of the page. The # symbol says, 'anchor' to a browser, and is (correctly) not passed as part of the URI/URL.

If $_GET['c'] does not work, you will need to change the character.
Information following the # should not be passed as part of the URI (maybe if you can 'escape it' by encoding, but I don't think so), because it is a browser message, not part of the location, and should not be interpreted or used by the server.

http://example.com?a=123&b=456&c=789#111

What the above 'says' is: 'Open the website example.com, pass the information a=123&b=456&c=789 to the location example.com, and jump to anchor 111 (<a name="111"></a>) on the page.'

Justin

I don't know if I would recommend using a 'standard' php comment symbol as part of a passed variable anyway.
Might be better to use a different character.

If you need to set the location, you could probably pass the same information twice: a=123&b=456&c=789&d=111#111