Hi guys im having a little problem with a script im doing, hoping if anyone has any ideas. Basically i set a cookie earlier on in my script, and im now on a page which i want to display if the user has the cookie, if the cookie is not there, i want them 2 be rediected to a diffeent page (signin.php)
here is my script so far:
PHP Code:
<html>
<body>
<?php
if (!isset($_COOKIE['user']))
echo "you are signed in";
else {
header ( "Location: signin.php" ); }
?>
<br />Click <a href="signout.php">here</a> to log out
</body>
</html>
It seems fine except that whe the cookie is not set, it doesnt redirect, bit pointless!
ok i have slightly changed the script now, this was more of a method of checking to see if the cookie was set. When i delete the set cookie i get the below error message:
"Warning: Cannot modify header information - headers already sent by (output started at C:\Documents and Settings\Mike\My Documents\Test Folder\Login-mytry\example1.php:3) in C:\Documents and Settings\Mike\My Documents\Test Folder\Login-mytry\example1.php on line 7"
So something is still wrong with my header re-direct. I have been doing some research, do i need to use a meta re-direct? what ever that is?
here is my new PHP code:
PHP Code:
<html>
<body>
<?php
if (isset($_COOKIE["user"]))
echo "Welcome " . $_COOKIE["user"] . "!<br />";
else
header("Location: signin.php");
?>
Click <a href="signout.php">here</a> to log out
</body>
</html>
ok i seem to have fixed it! its because i was sending the tags <html> and <body> to the HTTP before the redirect! so if anyone is inerested here is my new code.
<?php
if (isset($_COOKIE["user"]))
echo "Welcome " . $_COOKIE["user"] . "!<br />";
else
header("Location: signin.php");
?>
<html>
<body>
Click <a href="signout.php">here</a> to log out
</body>
</html>
And i works
Bookmarks