JoHa
JoHa

Reputation: 2039

Getting FULL URL with #tag

Tried to print the $_SERVER array in PHP, yet I can't find what I want:

http://www.domain.com/#sometaginpage

I want the "sometaginpage".

Help. Thanks!

Upvotes: 7

Views: 25496

Answers (3)

jrn.ak
jrn.ak

Reputation: 36619

Fairly certain that #hashtags are NOT sent to the server, but you could develop a workaround with AJAX:

some-page.html:

<script type="text/javascript">
    $(document).ready(function() {
        $(window).bind('hashchange', function() {
            var hash = window.location.hash.substring(1);
            $.get('ajax-hash.php', { tag: hash },
                function(data) { $('#tag').html(data); }
            );
        });
    });
</script>

<div id="tag"></div>
<a href="#one">#one</a> | <a href="#two">#two</a> | <a href="#lolwut">#lolwut</a>

ajax-hash.php:

<?php
    $hash = isset($_GET['tag']) ? $_GET['tag'] : 'none';
    echo $_SERVER['HTTP_REFERER'] . '#' . $hash;
?>

Note: This is dependent on the browser actually sending the HTTP_REFERER.. Since it's done through jQuery, it SHOULD.. but no promises! (Antivirus/Firewalls love to strip that from your packets)

Upvotes: 4

Sean Walsh
Sean Walsh

Reputation: 8344

The browser doesn't actually send anything that comes after the hash(#) to the server because it is resolved within the browser.

Upvotes: 9

John
John

Reputation: 1540

I'm not sure if $_SERVER['REQUEST_URI'] will give it or not. s992 might be right, it may not send that to the server.

Upvotes: 0

Related Questions