Set cookie with hash value

Discussion in 'JavaScript' started by tianbo84, Oct 25, 2009.

  1. #1
    Hi there - first off I don't know javascript at all but I am wondering if some could take a quick look at my script and see why it might not be working.


    Basically I have a url like "www.someurlisgoinghere.com/#id=190" - I would like to get the 107 and put it in a cookie to retrieve later with php.

    Here's my script that I cannot seem to get working properly. (the first part is suppose to get the hash value and the second is to set the cookie.

    <script type="text/javascript">
    	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;
    }
                var cookieData = getUrlVars()["id"];
                if (cookieData != null) {
                var cookieName = "referrer";
                var days = 5;
                var expires = new Date ();
                expires.setTime(expires.getTime() + days * (24 * 60 * 60 * 1000)); 
                
                SetCookie(cookieName, cookieData, expireDate) }
    </script>
    Code (markup):
    I am just using this to grab it with php

    $user_refer = $_COOKIE['referrer'] ;
    Code (markup):
    Thanks a lot guys
     
    tianbo84, Oct 25, 2009 IP