943,919 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1326
  • PHP RSS
Mar 18th, 2008
0

setcookies ()

Expand Post »
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..
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
evios is offline Offline
60 posts
since Sep 2007
Mar 18th, 2008
0

Re: setcookies ()

Do you have any html tag or any echo statement ? Can you post your code ?
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Mar 18th, 2008
0

Re: setcookies ()

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 Syntax (Toggle Plain Text)
  1.  
  2. <?php
  3. setcookie($username, time()+3600);
  4. mysql_connect("localhost", "root", "1234") or die(mysql_error());
  5. mysql_select_db("userlist") or die(mysql_error());
  6. $username=$_POST['username'];
  7. $password=$_POST['password'];
  8. $query = "SELECT * FROM user where username='$username' && password='$password'";
  9. $result = mysql_query($query) or die(mysql_error());
  10. if ($username=="admin" && $password=="admin1234")
  11. {
  12. echo "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />";
  13. echo "<center><h1>Administrator logged in!!!</h1></center>";
  14. echo "<center><h1>Please wait to be directed to the administrator page.....</h1></center>";
  15. echo "<meta http-equiv=\"refresh\" content=\"5;url=trytolink.php\">";
  16. }
  17. else if(mysql_num_rows($result) > 0)
  18. {
  19. echo "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />";
  20. echo "<center><h1>You had sucessfully logged in as ".$username ."</h1><br/></center>";
  21. echo "<center><h1>Please <a href='registration.php'>Click here</a> to update your details or
  22. <a href='claim_try.php'>Click here</a> to the claim page.</h1></center>";
  23. }
  24.  
  25. else
  26. {
  27. echo "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />";
  28. echo "<center><h1>Sorry! Your username and password is incorrect!!! Please try again!!!</h1></center>";
  29. echo "<meta http-equiv=\"refresh\" content=\"5;url=index3.php\">";
  30. }
  31. ?>
  32. <html>
  33. <head>
  34. <title>::. ISO CLAIM PAGE</title>
  35. <link rel="stylesheet" type="text/css"
  36. href="my.css">
  37. </head>
  38. <body>
  39. </body>
  40. </html>
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
evios is offline Offline
60 posts
since Sep 2007
Mar 18th, 2008
0

Re: setcookies ()

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!
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Mar 18th, 2008
0

Re: setcookies ()

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:
PHP Syntax (Toggle Plain Text)
  1. ......
  2. <form method="post" action="claim_try2.php">
  3. <div><label>Name:<?php echo $_COOKIE["username"];?></label><br></div>
  4. <div><label for="type">Department:</label>
  5. <select name="department">
  6. <optgroup label="---SELECT---">
  7. <option>KKK</option> <option>KEE</option> <option>KPM</option>
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
evios is offline Offline
60 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Anyone who can help?
Next Thread in PHP Forum Timeline: download from one server to another





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC