1

I'd like on PHP get the requested URI.

I mean to store into $address the string www.mywebsite.com/index.php?param=1 for example.

Thanks

Matt
  • 22,721
  • 17
  • 71
  • 112
kwichz
  • 2,363
  • 5
  • 23
  • 25

2 Answers2

4

The path without domain name is stored in $_SERVER['REQUEST_URI']. In your case, it would be /index.php?param=1.

Tim
  • 13,904
  • 10
  • 69
  • 101
  • Domain name is in `$_SERVER['HTTP_HOST']` – Zirak May 14 '11 at 19:19
  • @Zirak: I hesitated to include that in my answer since the PHP manual [made me suspicious](http://stackoverflow.com/questions/6004298/when-could-the-http-host-header-be-undefined). – Tim May 14 '11 at 19:27
2
$address = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
Emil Vikström
  • 90,431
  • 16
  • 141
  • 175