login  Naam:   Wachtwoord: 
Registreer je!
 Forum

Cookies

Offline SvenP - 12/05/2005 12:52 (laatste wijziging 12/05/2005 12:52)
Avatar van SvenPPHP interesse op andere site word ik niet echt geweldig geholpen..
dus laat ik het hier maar probeeren...^^

ik heb nog nooit eerder moet cookies gewerkt,
maar ik wil mijn site cookie-enebled maken.
dus met sessies en cookies..
echter, geeft da ding een foutmelding als hij de cookie aan moet maken (setcookie):

  1. Warning: Cannot modify header information - headers already sent by (output started at /usr/opt/usr/wa4o6920633/DOMAIN/HTML/ts/level/home.php:17) in /usr/opt/usr/wa4o6920633/DOMAIN/HTML/ts/php/login.php on line 15


dit is login.php:
  1. <?php
  2. if($session){
  3. echo "You are already logged in.";
  4. }else{
  5. #########################################
  6. if($_SERVER['REQUEST_METHOD'] == POST){
  7. $username = $_POST['username'];
  8. $password = md5($_POST['password']);
  9. $b_cookie = $_POST['cookie'];
  10.  
  11. $query = mysql_query("SELECT * FROM `ts_members` WHERE `username`='$username' AND `password`='$password'");
  12. $check = mysql_fetch_object($query);
  13. if(mysql_num_rows($query) != 0 && $check->activated == 1){
  14. if($b_cookie == ON){
  15. setcookie("treadstone", "$username", time()+3600*24,"/",".a4o.nl",1);
  16. }else{
  17. $_SESSION['ts'] = $username;
  18. }
  19. echo "<table width=\"90%\" cellSpacing=\"0\" cellPadding=\"2\" border=\"1\" bordercolor=\"#000000\" style=\"border-collapse: collapse\" align=\"center\">";
  20. echo "<tr><td><b>Login</b></td></tr>";
  21. echo "<tr><td>You are logged in successfully. $b_cookie </td></tr>";
  22. echo "</table>";
  23. echo "<meta http-equiv=\"refresh\" content=\"1; url=index.php\">";
  24.  
  25. }else{
  26. echo "<table width=\"90%\" cellSpacing=\"0\" cellPadding=\"2\" border=\"1\" bordercolor=\"#000000\" style=\"border-collapse: collapse\" align=\"center\">";
  27. echo "<tr><td><b>ERROR</b></td></tr>";
  28. echo "<tr><td>Login Failure:<br>
  29. 1. Wrong Username or Password<br>
  30. 2. Empty Fields<br>
  31. 3. Account UnActivated";
  32. echo "</table>";
  33. }
  34. }else{
  35. ?><FORM ACTION="<? $_SERVER['PHP_SELF'] ?>" METHOD="POST"><?
  36. echo "<table width=\"90%\" cellSpacing=\"0\" cellPadding=\"2\" border=\"1\" bordercolor=\"#000000\" style=\"border-collapse: collapse\" align=\"center\">";
  37. echo "<tr><td width=\"25%\">Username:</td>";
  38. echo "<td width=\"75%\" align=\"center\"><input type=\"text\" style=\"width: 90%\" name=\"username\"></td></tr>";
  39. echo "<tr><td width=\"25%\">Password:</td>";
  40. echo "<td width=\"75%\" align=\"center\"><input type=\"password\" style=\"width: 90%\" name=\"password\"></td></tr>";
  41. echo "<tr><td width=\"25%\">Remember Me:</td>";
  42. echo "<td width=\"75%\" align=\"center\"><input type=\"checkbox\" name=\"cookie\" value=\"ON\"></td></tr>";
  43. echo "<tr><td colspan=\"2\"><input type=\"submit\" value=\"Login\"></td></tr>";
  44. echo "</table>";
  45. echo "</form>";
  46.  
  47. } }
  48. ?>

deze word geinclude in index.php.

kan iemand me mss helpen om de fout te verhelpen? 

4 antwoorden

Gesponsorde links
Offline Thomas - 12/05/2005 13:25
Avatar van Thomas Moderator cookies in PHP

het gebruik van ob_start
Offline SvenP - 12/05/2005 13:27
Avatar van SvenP PHP interesse header probleem is opgelost, dankje 

echter maakt hij de cookie niet aan 
Offline Thomas - 12/05/2005 13:50
Avatar van Thomas Moderator if($b_cookie == ON)

wordt dat dan wel uitgevoerd ? Alles uit $_POST is tekst.

Maak je trouwens gebruik van secure pagina's (https) ? Anders moet je die 1 in je cookie weglaten lijkt mij ? En dat subdomein / subdirectory... Ik weet zo gauw niet of dat goed is - haal dat eens weg en probeer het opnieuw.
Offline Legolas - 12/05/2005 15:10
Avatar van Legolas Onbekend over het algemeen is het een beetje slecht gescript, dit is beter:
  1. <?php
  2. if($_SESSION){
  3. $message = "You are already logged in.";
  4. }
  5. else{
  6. if($_SERVER['REQUEST_METHOD'] == 'POST'){
  7. $username = $_POST['username'];
  8. $password = md5($_POST['password']);
  9. $b_cookie = $_POST['cookie'];
  10. $query = mysql_query("SELECT * FROM `ts_members` WHERE `username`='".$username."' AND `password`='".$password."'");
  11. $check = mysql_fetch_assoc($query);
  12. if(mysql_num_rows($query) != 0 && $check['activated'] == 1){
  13. if($b_cookie == ON){
  14. setcookie("treadstone", $username, time()+3600*24,"/",".a4o.nl",1);
  15. }else{
  16. $_SESSION['ts'] = $username;
  17. }
  18. $message = "<table width=\"90%\" cellSpacing=\"0\" cellPadding=\"2\" border=\"1\" bordercolor=\"#000000\" style=\"border-collapse: collapse\" align=\"center\">";
  19. $message .= "<tr><td><b>Login</b></td></tr>";
  20. $message .= "<tr><td>You are logged in successfully. ".$b_cookie." </td></tr>";
  21. $message .= "</table>";
  22. $message .= "<meta http-equiv=\"refresh\" content=\"1; url=index.php\">";
  23.  
  24. }else{
  25. $message = "<table width=\"90%\" cellSpacing=\"0\" cellPadding=\"2\" border=\"1\" bordercolor=\"#000000\" style=\"border-collapse: collapse\" align=\"center\">";
  26. $message .= "<tr><td><b>ERROR</b></td></tr>";
  27. $message .= "<tr><td>Login Failure:<br>
  28. 1. Wrong Username or Password<br>
  29. 2. Empty Fields<br>
  30. 3. Account UnActivated";
  31. $message .= "</table>";
  32. }
  33. }else{
  34. ?><FORM ACTION="<? $_SERVER['PHP_SELF'] ?>" METHOD="POST"><?
  35. $message = "<table width=\"90%\" cellSpacing=0 cellPadding=2 border=\"1\" bordercolor=\"#000000\" style=\"border-collapse: collapse\" align=\"center\">";
  36. $message .= "<tr><td width=\"25%\">Username:</td>";
  37. $message .= "<td width=\"75%\" align=\"center\"><input type=\"text\" style=\"width: 90%\" name=\"username\"></td></tr>";
  38. $message .= "<tr><td width=\"25%\">Password:</td>";
  39. $message .= "<td width=\"75%\" align=\"center\"><input type=\"password\" style=\"width: 90%\" name=\"password\"></td></tr>";
  40. $message .= "<tr><td width=\"25%\">Remember Me:</td>";
  41. $message .= "<td width=\"75%\" align=\"center\"><input type=\"checkbox\" name=\"cookie\" value=\"ON\"></td></tr>";
  42. $message .= "<tr><td colspan=\"2\"><input type=\"submit\" value=\"Login\"></td></tr>";
  43. $message .= "</table>";
  44. $message .= "</form>";
  45. } }
  46. echo $message;
  47. ?>

Right??^^
Gesponsorde links
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2025 Sitemasters.be - Regels - Laadtijd: 0.191s