#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Php script that will check for cookie,if cookie yes go to url, if no run script


    Im trying to create a php script that will check for cookie. If cookie exist it goes to a page. If the cookie does not exist it it will run script.

    1. User visits index.php. seeing no cookie runs a script that directs user to gateway.php.
    2. Gateway.php page places cookie.
    3. User then picks between 2 options one of witch is the page he was just on.
    4. If user picks this option the script does not run because it sees cookie avoiding infinity loop.
    5. I only want to use php. Im trying to not use java script or anything.


    gateway.php
    PHP Code:
    <?php
         $value 
    "mobilecookie";
         
    /*setcookie(name,value,expire,path,domain,secure)*/
         
    setcookie("mobilecookie",$valuetime()+60*60*24*30);
    ?>
    index.php
    PHP Code:
    How would I code this?
    <?php
        
    if cookie exist go to url(index.php)
        if 
    cookie does not exist run script once(script.php)
    ?>
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    please read the manual, especially the part on $_COOKIE.

    But be aware that some people block cookies.
  4. #3
  5. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,556
    Rep Power
    2338
    Read the manual and give it a try.
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!

IMN logo majestic logo threadwatch logo seochat tools logo