tags:

views:

18

answers:

1

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("location: 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?

+2  A: 

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.

M2tM