0

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;
SagarPPanchal
  • 9,839
  • 6
  • 34
  • 62
user3230561
  • 445
  • 1
  • 10
  • 21
  • 1
    the hash tag part is not send to the server, this is only used to scroll to a certain element or in javascript – EaterOfCode Apr 01 '14 at 09:29
  • 2nd url part, Javascript can do that. – Rahil Wazir Apr 01 '14 at 09:29
  • the "#tag" is not sent to the server so the only way to do this would be with some javsscript to send it manually – Rene Koch Apr 01 '14 at 09:30
  • Take a look here: http://stackoverflow.com/questions/6768793/get-the-full-url-in-php Hope this do the magic. – Tyralcori Apr 01 '14 at 09:31
  • @user3230561 consider accepting my answer to prevent this question from getting more unneeded attention, or if my answer didn't solve your problem, use the comments section to ask for further detail. – Andresch Serj Apr 28 '14 at 09:54

3 Answers3

1

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.

Andresch Serj
  • 35,217
  • 15
  • 59
  • 101
0

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']

Amit Bera
  • 7,581
  • 7
  • 31
  • 57
0

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.

Uriziel
  • 177
  • 1
  • 10