Forum Moderators: coopster
if (!isset($_COOKIE[name])) {
setcookie("name", $stuff, time()+36000);
}
However I have some pages on my site where it does it like this, like checking if variable is set...
if (!isset($name)) {
setcookie("name", $stuff, time()+36000);
}
Is this a valid way to do it too? Both appear to work fine.
With REGISTER_GLOBALS turned on, the $name variable could come from $_GET, $_POST, $_SERVER or $_COOKIE. In some cases that can have serious security implications if you don't check all your input variables.
eg. Someone can add "?name=newname" and that value will show up as $name (but not as $_COOKIE["name"]).
Clear as mud?
Secondly it is a big security risk.
i.e.
if i call your page as:
http:// yourdomain/yourpage.php?name=Vincent
then
$_COOKIE[name]=""
BUT
$name="Vincent"
i.e. cookie values can be overridden by putting variables in the URL path - just imagine if someone were to call your page as /yourpage.php?admin=Yes ... it would take only guessing the right variable name!
Is there a bit of code I could chuck into my existing forms which would automatically get all the values submitted in $_POST and name them with their variable name, as it were?
For example, if I had the values
$_POST['username']
$_POST['usertel']
$_POST['useremail']
$username
$usertel
$useremail