Hey,
I was wondering how to obtain a hash value and pass it to php.
URL:
http://www.mydomain.com/#id=110
All I want to grab is just the "110".
This is my javascript code:
<script>
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('#') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
</script>
This is how I am going to call the value of the hash:
var first = getUrlVars()["id"]; // <-- name of hash
So my question is, first is this the proper javascript to grab the hash value?
Second how would I pass the hash value to a php variable? (the variable is going to be used to set a cookie)
ie:
$refer_id = $_GET['refer']; //<-- Grab this from javascript (the value of the hash)
$days = 5;
$date_of_expiry = time() + 60 * 60 * 24 * $days ;
setcookie( "referrer", $refer_id, $date_of_expiry );
Thanks