Muhammad Usman
Muhammad Usman

Reputation: 10956

how to capture the current page url in PHP

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

Upvotes: 2

Views: 516

Answers (3)

shadyyx
shadyyx

Reputation: 16065

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

Upvotes: 0

Chris Gessler
Chris Gessler

Reputation: 23123

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

?>

Upvotes: 0

ziad-saab
ziad-saab

Reputation: 20269

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.

Upvotes: 4

Related Questions