Trouble with PHP and Cookie set as Variable
I have this script to check that a cookie is on the computer, and then use the info from that cookie to take someone to the right page on my website. Here is the code
<?php
if (isset($_COOKIE["name"]))
$name = $_COOKIE["name"];
header("l开发者_开发百科ocation: names/$name/$name.php");
else
echo "You have no name";
?>
When this script is run, it does nothing. Not even echo "You have no name". Any ideas why this code won't work?
You are missing brackets. Maybe you are used to python?
<?php
if (isset($_COOKIE["name"])){
$name = $_COOKIE["name"];
header("location: names/$name/$name.php");
}else{
echo "You have no name";
}
?>
The syntax error with else is probably causing the script to fail and you may have error reporting turned off. Turn it on.
精彩评论