Hi,
I have register_globals and track_vars enabled in my php.ini file and I'm wondering that if i'm using values in HTTP_COOKIE_VARS, which function should i use to see if the data is set or valid.
Should i use isset or empty?
My arguments is as follows:
IF i use isset, which i've seen is common, if ( isset($HTTP_COOKIE_VARS["id"]) ) ... this function return true if it exists. Now i know that the entire associative array exists will it return false if there empty data say "" or that it is undefined.
IF i use empty, will it return true, if ( empty($HTTP_COOKIE_VARS["id"]) ), doesn't exist (not defined) or has no value ("").
i'm setting a cookie id with randomly generated number
which one is better practice and which one is does more type checking, etc.?
This is my code below:
<?php
$SECS_PER_DAY = "86400";
$NUMBER_OF_DAYS = "30";
$id = HTTP_COOKIE_VARS["id"];
//if there's a valid cookie set
if ( isset($id) ) {
//if the html form has been submmitted with a valid filesrc
if ( isset($HTTP_POST_VARS["filesrc"]) ) {
header( "Location http://www.domain.com/downloads/$filesrc" );
} else {
//most likely the user typed in the url in the location bar
header( "Location http://www.domain.com/downloads/error.php" );
}
exit;
} else {
//set the cookie and expiration date
//create a random unique id
srand((double)microtime()1000000);
$randval = rand();
//set the expiration time in seconds
$EXPIRATION = time() + $NUMBER_OF_DAYS $SECS_PER_DAY;
setcookie("id", $randval, $EXPIRATION, "/");
?>