Redirect unique visitors

total.load

Newbie
Joined
Jan 24, 2012
Messages
22
Reaction score
2
I've found this JS code, that set cookie:
<script type="text/javascript">
function redirect(){
var thecookie = readCookie('doRedirect');
if(!thecookie){window.location = 'redirect to';
}}function createCookie(name,value,days){if (days){var date = new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires = "; expires="+date.toGMTString();}else var expires = "";document.cookie = name+"="+value+expires+"; path=/";}function readCookie(name){var nameEQ = name + "=";var ca = document.cookie.split(';');for(var i=0;i < ca.length;i++){var c = ca;while (c.charAt(0)==' ') c = c.substring(1,c.length);if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);}return null;}window.onload = function(){redirect();createCookie('doRedirect','true','999');}


What I must modify, so the cookie 'll expire every 24h? And how I must save it(as a index) ?
 
Replace '999' with '1', it seems the function createCookie's 3rd parameter is "days" so 1 will be 24 hours.

As for the second part of your question, I don't get what you mean.
 
Forget about my first post.
I've managed to build this:
PHP:
   <?php
    //Checks if there is a cookie
    if(isset($_COOKIE["cookiename"])) //if cookie is set
    {
          header("Location: redirectDOTcom"); //redirect to
    }
    else
   
    setcookie( "cookiename", "something", time()+3600*24, "", "domainname" ); //set cookie name, variable and expiring time
    {
       header("Location: redirectuniquehit "); //redirect the unique view
    }
     
    ?>

The cookie is successful set, and after setting the cookie it redirect the unique visit. The problem is, when I go to the web-page 2nd time, it's redirecting me as a unique view, even if the cookie is set.
What I have to edit, to make it working?
 
misplaced {
PHP:
    <?php
    //Checks if there is a cookie
    if(isset($_COOKIE["cookiename"])) //if cookie is set
    {
          header("Location: redirectDOTcom"); //redirect to
    }
    else
    {
       setcookie( "cookiename", "something", time()+3600*24, "", "domainname" ); //set cookie name, variable and expiring time    
       header("Location: redirectuniquehit "); //redirect the unique view
    }
     
    ?>
 
Back
Top