Reputation: 445
How to get address in the browser using php. I want a way in which I can fetch the url value that is present in the browser. If I manually add a #tag to the existing url then I want to retrieve that as well.
I have used this code till now, but I want to retrieve https or http whatever value is in the browser.
Also this is my url: http://example.com/xyz/?p=65
but suppose I build up the 2nd url manually then I would like to retrieve that as well http://example.com/xyz/?p=65#fsgsg
$Path=$_SERVER['REQUEST_URI'];
echo $URI= 'http://'.$_SERVER['SERVER_NAME'].$Path;
Upvotes: 0
Views: 73
Reputation: 177
Your only option is to handle that parameter in javascript
because the # (hash) part wont get sent to the backend side, You can just detect click of the target element in JS
and then glue the # part as a parameter like '&hashValue=fsgsg'.
I hope that helps You in some way.
Upvotes: 0
Reputation: 7611
For getting has parameter,use below --
$url = 'http://amitbera.com/path?arg=value#anchor';
print_r(parse_url($url));
echo parse_url($url, PHP_URL_PATH);
More details in http://www.php.net/manual/en/function.parse-url.php
Also,For gettting arg value use $_SERVER['QUERY_STRING']
Upvotes: 0
Reputation: 37388
The part behind the # is not delivered to the browser. You could however run a tiny javascript that sends you that information since it is available to the DOM (But do you really want that?) via the window object.
Upvotes: 1