I’m trying to set all active cookies to variables in which the names would correspond to the name of the cookie, which I tried to accomplish using a variable variable. http://php.net/manual/en/language.variables.variable.php
function setcookie_vars() {
if(isset($_SERVER["HTTP_COOKIE"])) {
$cookies = explode(";", $_SERVER["HTTP_COOKIE"]);
foreach($cookies as $cookie) {
$parts = explode("=", $cookie);
$name = trim($parts[0]);
$value = trim($parts[1]);
$$name = $value;
return $$name;
}
}
}
print_r(${$test}); // should output the value for $_COOKIE["test"];
For instance, if the cookie’s name was “test,” the variable’s name would be $test with the same value set in the cookie for that name. I tried to test this out with cookies set beforehand and I got (and I checked that the cookie was already set):
Notice: Undefined variable: test in...
Notice: Undefined variable: in...
I was unable to find any problem similar to this on the web, probably because it’s fairly customized.
replace your entire function with: