setcookies ()
just wanna ask..if session cant be use, i try setcookies() to get the variable pass through the pages, however i get this error message:
Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\VertrigoServ\www\logincheck.php:2) in C:\Program Files\VertrigoServ\www\logincheck.php on line 3
i put setcookie($username, time()+3600); right after the mysql_connect(), and below it juz a normal function to differentiate between user and admin...
juz curious what is the mistake here and how can i declare the code? Thanks so much for helping..
evios
Junior Poster in Training
60 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
Do you have any html tag or any echo statement ? Can you post your code ?
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
hey..is you..hihi...
well, i setcookies() right after the user had logged in and the variables pass to the page shown below, i put it at the top right after <?php.....
<?php
setcookie($username, time()+3600);
mysql_connect("localhost", "root", "1234") or die(mysql_error());
mysql_select_db("userlist") or die(mysql_error());
$username=$_POST['username'];
$password=$_POST['password'];
$query = "SELECT * FROM user where username='$username' && password='$password'";
$result = mysql_query($query) or die(mysql_error());
if ($username=="admin" && $password=="admin1234")
{
echo "";
echo "<center><h1>Administrator logged in!!!</h1></center>";
echo "<center><h1>Please wait to be directed to the administrator page.....</h1></center>";
echo "<meta http-equiv=\"refresh\" content=\"5;url=trytolink.php\">";
}
else if(mysql_num_rows($result) > 0)
{
echo "";
echo "<center><h1>You had sucessfully logged in as ".$username ."</h1><br/></center>";
echo "<center><h1>Please <a href='registration.php'>Click here</a> to update your details or
<a href='claim_try.php'>Click here</a> to the claim page.</h1></center>";
}
else
{
echo "";
echo "<center><h1>Sorry! Your username and password is incorrect!!! Please try again!!!</h1></center>";
echo "<meta http-equiv=\"refresh\" content=\"5;url=index3.php\">";
}
?>
<html>
<head>
<title>::. ISO CLAIM PAGE</title>
<link rel="stylesheet" type="text/css"
href="my.css">
</head>
<body>
</body>
</html>
evios
Junior Poster in Training
60 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
There must be a whitespace before <?php . Check it out ! There shouldn't be any whitespace, any echo statements or any html tags before setcookie! :)
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
oh..thanks, i not even notice about that also. So the cookies had been set with $username and timeout 1 hour.....Then from this page, i click to another page, using the same syntax for set cookies () declared at the top before any header or echo....and again i try to retrieve my username so that it can show on the page, however i found that it is blank.
Here is the code i use to show the $username out:
......
<form method="post" action="claim_try2.php">
<div><label>Name:<?php echo $_COOKIE["username"];?></label></div>
<div><label for="type">Department:</label>
<select name="department">
<optgroup label="---SELECT---">
<option>KKK</option> <option>KEE</option> <option>KPM</option>
evios
Junior Poster in Training
60 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0