Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Logowanie php (sesje), Coś nei tak z tą sesją :/
miras
post 1.04.2011, 20:44:40
Post #1





Grupa: Zarejestrowani
Postów: 1 004
Pomógł: 9
Dołączył: 18.01.2011
Skąd: Siedlce

Ostrzeżenie: (30%)
XX---


Witam... postanowaiłem sobie coś spróbować z logowaniem i oto efekt - niby działa ale wyskakuje taki błąd : '
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/p93798/public_html/sklep/index.php:11) in /home/p93798/public_html/sklep/index.php on line 2



Kod:
  1. <?php
  2. session_register("zalogowany");
  3.  
  4. if(empty($_SESSION["zalogowany"]))$_SESSION["zalogowany"]=0;
  5.  
  6. mysql_connect("localhost", "xxx", "******")or die("Nie można nawiązać połączenia z bazą");
  7. mysql_select_db("xxx")or die("Wystąpił błąd podczas wybierania bazy danych");
  8.  
  9. function ShowLogin($komunikat=""){
  10. echo "$komunikat<br>";
  11. echo "<form action='index.php' method=post>";
  12. echo "Login: <input type=text name=login><br>";
  13. echo "Hasło: <input type=text name=haslo><br>";
  14. echo "<input type=submit value='Zaloguj!'>";
  15. echo "</form>";
  16. echo "Jeśli nie jesteś zarejestrowany, <a href='rejestruj.php'>tu znajdziesz formularz</a>";
  17. }
  18.  
  19. ?>
  20. <!DOCTYPE html
  21. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  22. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  23. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
  24. <head>
  25. <title>Strona główna</title>
  26. </head>
  27. <body>
  28. <?php
  29. if($_GET["wyloguj"]=="tak"){$_SESSION["zalogowany"]=0;echo "Zostałeś wylogowany z serwisu";}
  30. if($_SESSION["zalogowany"]!=1){
  31. if(!empty($_POST["login"]) && !empty($_POST["haslo"])){
  32. if(mysql_num_rows(mysql_query("select * from users where user_login = '".htmlspecialchars($_POST["login"])."' AND user_haslo = '".htmlspecialchars($_POST["haslo"])."'"))){
  33. echo "Zalogowano poprawnie. <a href='index.php'>Przejdź na stronę główną</a>";
  34. $_SESSION["zalogowany"]=1;
  35. }
  36. else echo ShowLogin("Podano złe dane!!!");
  37. }
  38. else ShowLogin();
  39. }
  40. else{
  41. ?>
  42. Gratulacje! Zalogowałeś się pomyślnie! Możesz przejśc teraz do innych podstron, np. do <a href="stronka.php">tej</a>
  43. <br><a href='index.php?wyloguj=tak'>wyloguj się</a>
  44. <?php
  45. }
  46. ?>
  47.  
  48. </body>
  49. </html>
  50. <?php mysql_close(); ?>


Ten post edytował miras 1.04.2011, 20:45:59


--------------------
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
peter13135
post 2.04.2011, 09:06:22
Post #2





Grupa: Zarejestrowani
Postów: 1 447
Pomógł: 191
Dołączył: 26.03.2008

Ostrzeżenie: (0%)
-----


przes session_start() nic nie może być wysyłane do przeglądarki (żadne echo, żaden print).

Ten post edytował peter13135 2.04.2011, 09:06:39


--------------------
:)
Go to the top of the page
+Quote Post
gregory90
post 2.04.2011, 10:49:34
Post #3





Grupa: Zarejestrowani
Postów: 9
Pomógł: 1
Dołączył: 3.10.2009

Ostrzeżenie: (0%)
-----


Można też wykorzystać funkcje ob_start() i ob_end_flush() .
Wszystko świetnie opisane w manualu oczywiście.
Go to the top of the page
+Quote Post
greycoffey
post 2.04.2011, 18:10:08
Post #4





Grupa: Zarejestrowani
Postów: 320
Pomógł: 29
Dołączył: 3.04.2010

Ostrzeżenie: (20%)
X----


Kolejny kurna sie znalazł co nie potrafi szukać...
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 10:44