Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][MySQL] Logowanie i sesje
Forum PHP.pl > Forum > Przedszkole
Traper21
Witam wszystkich smile.gif
Mam taki o to skrypt logowania:
  1. <?php
  2. ?>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  4. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
  6. <head>
  7. <title>tytul</title>
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9. <meta name="Description" content="asd" />
  10. <meta name="Keywords" content="asd" />
  11. <meta name="author" content="autor" />
  12. <link rel="stylesheet" href="../style.css" type="text/css" media="screen" />
  13. </head>
  14. <body>
  15. <div id="wrapper">
  16. <div id="top">
  17. <h1><a class="nazwa" href="#">klan</a> <span>:: admin</span></h1>
  18. <a class="kanal" href="#">chan</a>
  19. </div>
  20. <hr class="linia"></hr>
  21. <div id="bar"><span class="logowanie"><a href="#">admin</a></span><em>Ehhh:</em> 5 days</div>
  22. <hr class="linia"></hr>
  23. <div id="formlogin">
  24. <?php session_start();
  25.  
  26. $login=$_POST['login'];
  27. if(isset($login)) {
  28.  
  29. $admin=$_POST['username'];
  30. $haslo=md5($_POST['password']);
  31.  
  32. include('../db.php');
  33. $zapytanie = mysql_query("SELECT * FROM admin WHERE uzytkownik='$admin' AND haslo='$haslo'");
  34. if(mysql_num_rows($zapytanie) > 0) {
  35. $_SESSION['logged'] = $admin;
  36. header("Location: secret.php");
  37.  
  38. } else {
  39. echo "Podales zle dane";
  40. }
  41. }
  42. ?>
  43. <br /><h3>Logowanie</h3><br />
  44. <form method="post" action="login.php">
  45. <fieldset>
  46. <input type="text" name="username" class="pole" value="login" /><br />
  47. <input type="password" name="password" class="pole" value="haslo" /><br />
  48. <input type="submit" name="login" class="wysylaj" value="zaloguj się" />
  49. </fieldset>
  50. </form>
  51. </div>
  52. <hr class="linia"></hr>
  53. Š Strona
  54. </div>
  55. </body>
  56. </html>
  57. <?php ob_end_flush(); ?>


Lecz przy wejsciu na strone dostaję komunikat:
  1. <?php
  2. Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:VertrigoServwwwlistadminlogin.php:1) in C:VertrigoServwwwlistadminlogin.php on line 25
  3.  
  4. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:VertrigoServwwwlistadminlogin.php:1) in C:VertrigoServwwwlistadminlogin.php on line 25
  5. ?>


Co jest nie tak?
LBO
Problem wielokrotnie przerabiany na forum.

Przed uruchomieniem sesji, nie możesz nic wysłać do przeglądarki - niby twój skrypt jest poprawny. Możliwe jest jedna, że używasz kodowania UTF z tzw BOM (Byte Order Mark).

"ďťż" Na początku skryptu?

edit:

  1. <?php
  2. if (isset($_GET['regenerate'])) {
  3. }
  4. ?>
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  6. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9. <title><?=session_id()?></title>
  10. </head>
  11. <body>
  12. <p>Id sesji to <strong><?=session_id()?></strong></p>
  13. <ul>
  14. <li><a href="session.php?regenerate" title="">Nowa sesja</a></li>
  15. <li><a href="session.php" title="">Obecna sesja</a></li>
  16. </ul>
  17. </body>
  18. </html>
  19. <?php ob_end_flush(); ?>

Zapisz to do piku session.php. Jeżeli nadal wypluwa ten sam błąd, jest tak jak napisałem wcześniej.
Traper21
OMFG!

3h ślęczałem nad tym i nie wiedziałem dlaczego tak jest.
Z pomocą przyszedł mi wspaniały edytor PsPad, wybieramy FORMAT UTF-8 i już wszystko hula.
Notepad++ i zmiana za jego pomocą na UTF-8 psuje wszystko.

Ehhh wielkie dzięki za pomoc smile.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.