SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2006
    Location
    England, UK
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sending first-time visitors to a different page

    Hi. I want to add something so that if it is a visitor's first time visit, they are taken to another page. I know this is possible with javascript and cookies, but exactly what sort of code would I need to put in?

    An example of what I'm looking for can be seen at The Sims Resource (if it is your first time visit).
    Things currently working on: Multimedia content

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Better to do this on the server side. With PHP:
    PHP Code:
    <?php
    if (!$_COOKIE['visited']) header('Location:http://www.anotherpage.com');
    ?>
    That means that when someone visits for the first time, a cookie called "visited" is set.
    If you can't do this on the server side, with javascript read the cookie (you can find out how here: http://www.quirksmode.org/js/cookies.html ) and then if check if it's set and redirect if necessary:
    Code:
    if (!visitedcookie) window.location = 'http://www.anotherpage.com';


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •