If cookie is found, page is not redirecting
On index2.php, I am creating a cookie using the following code:
<?php
if ("" == "") {
setcookie("ipaddress", "".((isset($_SERVER["REMOTE_ADDR"]))?$_SERVER["REMOTE_ADDR"]:"") ."", time()+(60*60*24*30), "/", "", 0);
}
?>
On the main page, index.php, I have the following code:
<?php echo((isset($_COOKIE["ipaddress"]))?$_COOKIE["ipaddress"]:"") ?>
<?php // find the ip address cookie, if its set, redirect
if (isset($_cookie["ipaddress"])) {
// redirect
header ('Location: index2.php');
}
?>
The problem is, it's not redirecting. I've output the cookie on the page, so I know it's there, but I can't figure out why it's not redirecting to index2.php once it's found?
Thanks!