-2

hi in my code if there is no cookie show a page who set the cookie so the next time the user reaches the page will show another

if ((!isset($_COOKIE['app']) )){
        $plantilla->app_li();
        $val='desktop';
        $val1='app';
    echo setcookie($val1, $val, time() + (86400 * 2), '/');
    }else{
        echo $plantilla->home();
    }

if the cookie "app" exists shows $plantilla->home(); ,if not will show $plantilla->app_li(); and creat the cookie

but it dont create

jtaco263
  • 43
  • 1
  • 10

1 Answers1

0

Use $_COOKIE to retrieve a cookie with PHP. Once the cookies have been set, they can be accessed on the next page load.

$val1='app';

if(!isset($_COOKIE[$val1])) {
        $plantilla->app_li();
        $val='desktop';            
    echo setcookie($val1, $val, time() + (86400 * 2), '/');
} else {
   echo $plantilla->home();
}

Looking your question and answer this link http://www.pontikis.net/blog/create-cookies-php-javascript

bhavesh vala
  • 873
  • 7
  • 14
  • $cookie_name = 'pontikis_net_php_cookie'; if(!isset($_COOKIE[$cookie_name])) { print 'Cookie with name "' . $cookie_name . '" does not exist...'; } else { print 'Cookie with name "' . $cookie_name . '" value is: ' . $_COOKIE[$cookie_name]; } – bhavesh vala Dec 25 '14 at 06:50
  • tyr this http://stackoverflow.com/questions/10738593/check-if-a-php-cookie-exist-and-if-not-set-him-a-value – bhavesh vala Dec 25 '14 at 06:57