Web Analytics Made Easy -
StatCounter Help with entrance page cookie/redirection - CodingForum

Announcement

Collapse
No announcement yet.

Help with entrance page cookie/redirection

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with entrance page cookie/redirection

    I'm trying to find a way to allow visitors to my website who have already seen my entrance page to skip that and go directly to the main page.
    I'm not sure how to do this, or what my options are, but I think it's possible to do this with php and setting up a cookie.

    I found some code online for this task, but it didn't seem to work (I made sure to enable all cookies in my browser). It seems to generate the cookie because I can see the cookie file on my computer, but it still doesn't skip the entrance page like it's supposed to.

    Here is the code:

    setcookie("SOMETHING", "vistedmain", time()+60*60*24*30
    );

    $cookieinfo = $HTTP_COOKIE_VARS["SOMETHING"];


    if ($cookieinfo == "$cookieinfo") {
    include('main.html');
    exit;

    } else {
    include('page2.html');
    exit;
    }

    Does anybody have any suggestions, or know why the script isn't working?

  • #2
    this is kinda odd
    PHP Code:
    if ($cookieinfo == "$cookieinfo") { 
    try
    PHP Code:
    if($cookieinfo == "vistedmain"){ 
    also, try making it so that your if statement is not below the setcookie
    because obviously if you've set the cookie just above the if statement, it's going to think your first visit is not your first visit.

    however, just putting setcookie below your if statement will produce the "headers already sent" error... you need another if statement above the setcookie or just combine it all like this
    PHP Code:
    if(empty($_COOKIE['SOMETHING'])){
    setcookie("SOMETHING","vistedmain",time()+60*60*24*30);
    include(
    "main.html");
    }else{
    include(
    "page2.html");

    Last edited by boeing747fp; Oct 8, 2006, 01:28 AM.

    Comment


    • #3
      I think you solved the problem! Thanks alot for the quick response, I really appreciate it

      Comment

      Working...
      X