2

I want to get the current page URL with parameters in PHP

the URL is

http://localhost/omni/abc.php#def=S6ZT4b9MEsFGDzo

I want to get the url part after the # sign

Muhammad Usman
  • 10,426
  • 22
  • 72
  • 107

3 Answers3

4

Anything after the # in a URL is only handled on the client-side. It is not even passed to the request to the server, so there is no way you can directly access it.

ziad-saab
  • 19,139
  • 3
  • 36
  • 31
  • I looked long an hard for this a long time ago and found the same answer. I haven't tried it, but the OP might try an ajax function that calls a php script and deals with it that way, but depending on what the OP actually wants to do, this feels clumsy even as I suggest it. – TecBrat May 30 '12 at 12:51
  • Yes. Not only is it clumsy, but it will not be accessible by the page that is being loaded, only by a secondary AJAX request. – ziad-saab May 30 '12 at 12:55
0

Found this little niblet while researching the issue...

http://www.stoimen.com/blog/2009/04/15/read-the-anchor-part-of-the-url-with-php/

<script>

var query = location.href.split('#');

document.cookies = 'anchor=' + query[1];

<?php if (!$_COOKIE['anchor']) : ?>

window.location.reload();

<?php endif; ?>

<?php

echo $_COOKIE['anchor'];

?>
Chris Gessler
  • 22,727
  • 7
  • 57
  • 83
0

From this URL: http://localhost/omni/abc.php?def=S6ZT4b9MEsFGDzo

$_SERVER['HTTP_HOST'] -> localhost
$_SERVER['SCRIPT_URL'] -> omni/abc.php
$_SERVER['QUERY_STRING'] -> def=S6ZT4b9MEsFGDzo

OR

$_SERVER['REQUEST_URI'] -> omni/abc.php?def=S6ZT4b9MEsFGDzo

OR

$_SERVER['SCRIPT_URI'] -> http://localhost/omni/abc.php

shadyyx
  • 15,825
  • 6
  • 60
  • 95