Capture # hash value in the Url using PHP & JS

Hash value in a URL could not be captured using Pure PHP. We need to use javascript along with to capture it.

 

Here is example of it.

<?php

if(!isset($_GET['hash'])){
?>
<script>

var query = location.href.split(‘#’);

window.location.href=query[0]+’&’+query[1];
window.location.reload();
</script>
<?php
}

?>

 

 

Comments: 3

  1. Jonah Q. Mckenzie June 30, 2013 at 3:46 pm Reply

    In this programming tutorial, we will learn how to get url parameters and their values using javascript. Recently, while working on a project, i needed to get parameter values from url string of the current web page. So let’s have a look over how i made this happen.

  2. Hugo Howell July 27, 2013 at 2:55 am Reply

    We all know that php can read the url values of query string variables using $_REQUEST but foi yuo need to get the values of hash, PHP can’t really help. Some suggest to use parse_url() function but it can’t get the fragment values. Reason for this is that the browser won’t even send a request with a fragment part. The fragment part is resolved and remains in the browser, i.e. on client side.

  3. April E. Hoover September 11, 2013 at 1:44 am Reply

    i would need to have the value of v from the url using php. I understand it needs to be done using regex, but me not so good at it, I have checked the other related questions but i found issues with the way they resolved.