www.webdeveloper.com
Results 1 to 6 of 6

Thread: Cookies Check Script

  1. #1
    Join Date
    Apr 2005
    Location
    Behind my DiGiCo SD7 Console
    Posts
    900

    Cookies Check Script

    Hey!

    I use the following code to check to see if cookies are enabled. If they are enabled, the script will redirect to another page. If they are not enabled, it will redirect to a page that will tell the user to enable cookies.

    I get this error and it only redirects if cookies are enabled. If they are not, it does not display cookies.php

    PHP Notice: Undefined index: cookie_checked in /var/www/vhosts/mydomain.com/httpdocs/index.php on line 4

    PHP Code:
    <?php
    session_start
    ();
    if (
    $_SESSION['cookie_checked'])
    {
    if (
    $_COOKIE['cookie_checked'])
    {
    header("Location: login.php");
    } else {
    header("Location: cookies.php");
    }
    } else {
    $_SESSION['cookie_checked'] = 1;
    setcookie('cookie_checked'1);
    header("Location: $_SERVER[PHP_SELF]");
    }
    ?>
    Registered Linux User: #463250
    -----------------
    HELPFUL LINKS
    PHP - http://www.php.net
    Website Color Schemer - http://www.colorschemer.com/online.html

  2. #2
    Join Date
    May 2007
    Posts
    63

    cookie check

    Try amending your cookie check on line 4

    if (isset($_COOKIE["cookie_checked"]))

  3. #3
    Join Date
    Apr 2005
    Location
    Behind my DiGiCo SD7 Console
    Posts
    900
    I removed line 4, and then I got an error about an unexpected } on line 10 then I got a 500 error that said unexpected T_ELSE.

    Any ideas on this?
    Registered Linux User: #463250
    -----------------
    HELPFUL LINKS
    PHP - http://www.php.net
    Website Color Schemer - http://www.colorschemer.com/online.html

  4. #4
    Join Date
    Apr 2005
    Location
    Behind my DiGiCo SD7 Console
    Posts
    900
    Strike post #3.

    I tried that and I get the same undefined index error
    Registered Linux User: #463250
    -----------------
    HELPFUL LINKS
    PHP - http://www.php.net
    Website Color Schemer - http://www.colorschemer.com/online.html

  5. #5
    Join Date
    Apr 2005
    Location
    Behind my DiGiCo SD7 Console
    Posts
    900
    anything on this?
    Registered Linux User: #463250
    -----------------
    HELPFUL LINKS
    PHP - http://www.php.net
    Website Color Schemer - http://www.colorschemer.com/online.html

  6. #6
    Join Date
    Apr 2005
    Location
    Behind my DiGiCo SD7 Console
    Posts
    900
    Could someone be kind enough to check this out for me?
    Registered Linux User: #463250
    -----------------
    HELPFUL LINKS
    PHP - http://www.php.net
    Website Color Schemer - http://www.colorschemer.com/online.html

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles