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!


Solution 1:

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

Solution 2:

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)