i have read that the following code will not work:
Code: Select all
setcookie("Testcookie", $value);
// CHECK cookie
if(isset($_cookie['Testcookie'])){;
// do something
}
is the above paragraph true. if so, can i have a working code?
Moderator: General Moderators
Code: Select all
setcookie("Testcookie", $value);
// CHECK cookie
if(isset($_cookie['Testcookie'])){;
// do something
}
Hello,stevestark5000 wrote:i have read that the following code will not work:
cookie is browser side thingy, so it will not be available in the $_cookie array until sent by the browser. So in example above cookie will become available only after page is accessed second time.Code: Select all
setcookie("Testcookie", $value); // CHECK cookie if(isset([color=#FF0000]$_cookie[/color]['Testcookie'])){; [color=#FF0000]<- what is this? ;?// you sould type $_COOKIE instad of $_cookie (yes it matters! wont work either way)[/color] // do something }
is the above paragraph true. if so, can i have a working code?
Code: Select all
if (isset($_COOKIE["test"])){ //checks if the cookie "test" exists, If so execute you code
// your code
}else{
if (isset($_REQUEST["testing"])) //else > check if ther "testing" exist by "GET"
{
//msg if cookies disabled //if so , say that you cookies option on your browser is deisabled
}
else
{
setcookie("test", "1", 0, "/"); //else set the cookie
header("Location: $_SERVER[PHP_SELF]?testing=1"); //and reload the page with the "testing" var
}
}Code: Select all
if ($_SERVER['REQUEST_URI'] == "/" && (isset($_COOKIE[$myCookie]))) {
echo $_SERVER['REQUEST_URI'];
}
// $GLOBALS['core']->killAllSessions();
if (!$_SESSION['OBJ_user']->isUser()) {
$settings = $_SESSION["OBJ_user"]->getSettings();
if($settings["show_remember_me"])
$myCookie = PHPWS_User_Cookie::cookie_read("mod_users", "rememberme");
if(isset($myCookie)) {
$myCookie = preg_replace('/\W/', '', $myCookie);
$id = $GLOBALS["core"]->getOne("select user_id from mod_users where cookie='$myCookie'", TRUE);
if($id)
$_SESSION['OBJ_user']->loadUser($id, 1);
else
PHPWS_User::login_box();
} else {
PHPWS_User::login_box();
}
}