setcookies ()

Please support our PHP advertiser: 50% off 6 Months Dedicated Server Hosting from 1&1!
Reply

Join Date: Sep 2007
Posts: 60
Reputation: evios is an unknown quantity at this point 
Solved Threads: 0
evios evios is offline Offline
Junior Poster in Training

setcookies ()

 
0
  #1
Mar 18th, 2008
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..
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,833
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 344
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: setcookies ()

 
0
  #2
Mar 18th, 2008
Do you have any html tag or any echo statement ? Can you post your code ?
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 60
Reputation: evios is an unknown quantity at this point 
Solved Threads: 0
evios evios is offline Offline
Junior Poster in Training

Re: setcookies ()

 
0
  #3
Mar 18th, 2008
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.....
  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>
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,833
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 344
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: setcookies ()

 
0
  #4
Mar 18th, 2008
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!
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 60
Reputation: evios is an unknown quantity at this point 
Solved Threads: 0
evios evios is offline Offline
Junior Poster in Training

Re: setcookies ()

 
0
  #5
Mar 18th, 2008
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:
  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>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum


Views: 1090 | Replies: 4
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC