Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySql/PHP] sesje
fran1o
post 4.05.2008, 14:05:35
Post #1





Grupa: Zarejestrowani
Postów: 65
Pomógł: 2
Dołączył: 15.04.2008

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


Witam
Szukam bledu i nie moge znalezc...
  1. <?php
  2.  
  3. $mysql_host = "localhost";
  4. $mysql_login = "root";
  5. $mysql_pass = "";
  6. $mysql_baza = "baza2";
  7. $mysql_tabela = "users";
  8.  
  9.  
  10. // Wylogowanie i zalogowanie z ustaleniem sesji
  11.  
  12.  
  13. $users_login = $_POST['login'];
  14. $users_pass = $_POST['haslo'];
  15.  
  16. if($_GET['login']=="koniec") { //wylogowanie
  17. sesion_destroy();
  18. }
  19.  else if($users_login<>"" and $users_pass<>"") {
  20.  $users_pass = md5($users_pass);
  21.  if($baza = mysql_connect($mysql_host, $mysql_login, $mysql_haslo)) {
  22. if(mysql_select_db($mysql_baza)) {
  23. $wynik = mysql_query("SELECT * FROM $mysql_tabela WHERE users_login='$users_login' and users_pass='$users_pass'") or die(mysql_error());
  24.  if(mysql_num_rows($wynik)==1) {
  25.  $dane = mysql_fetch_array($wynik);
  26.  $_SESSION['zalogowany']="tak";
  27.  $_SESSION['login']=$dane['login'];
  28.  
  29.  }
  30. } else echo "Nie można się połączyć z bazą";
  31. mysql_close($baza);
  32. }
  33. }
  34.  
  35. // Panel formularza do zalogowania i wylogowania 
  36.  
  37. if($_SESSION['zalogowany']=="tak") {
  38. echo "<p>Witaj <b>".$_SESSION['login']."</b></p>";
  39. echo "<br><a href=\"index.php?login=koniec\">Wyloguj się</a>";
  40. }
  41. else{
  42. echo <<<KONIEC
  43. <form action="index.php" method="post">
  44. <table>
  45. <tr>
  46. <td>Login:</td>
  47. <td><input type="text" name="login" /></td>
  48. </tr>
  49. <tr>
  50. <td>Haslo:</td>
  51. <td><input type="password" name="haslo" /></td>
  52. </tr>
  53. <tr>
  54. <td colspan="2" align="center">
  55. <input type="submit" value="zaloguj" /> 
  56. </td>
  57. </tr>
  58. </table>
  59. KONIEC;
  60.  
  61. }
  62. if($_SESSION['zalogowany']=="tak") {
  63. echo "<p>Tekst widzi osoba zalogowana</p>";
  64. }
  65.  
  66. ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 10)
Piniek
post 4.05.2008, 14:07:10
Post #2





Grupa: Przyjaciele php.pl
Postów: 463
Pomógł: 49
Dołączył: 27.12.2007
Skąd: Warszawa

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


a wyskakuje jakiś błąd, jeżeli tak to jaki ?


--------------------
Go to the top of the page
+Quote Post
l0ud
post 4.05.2008, 14:09:55
Post #3





Grupa: Zarejestrowani
Postów: 1 387
Pomógł: 273
Dołączył: 18.02.2008

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


Napisz chociaż czym objawia się ten błąd.


--------------------
XMPP: l0ud@chrome.pl
Go to the top of the page
+Quote Post
fran1o
post 4.05.2008, 14:52:04
Post #4





Grupa: Zarejestrowani
Postów: 65
Pomógł: 2
Dołączył: 15.04.2008

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


po pierwsze
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Program Files\WebServ\httpd-users\test2\index.php:1) in C:\Program Files\WebServ\httpd-users\test2\formularz_przetagi.php on line 3

po drugie to nic sie nie dzieje nawet jak podam login i pass
Go to the top of the page
+Quote Post
b4x
post 4.05.2008, 14:54:16
Post #5





Grupa: Zarejestrowani
Postów: 658
Pomógł: 95
Dołączył: 20.12.2005
Skąd: N54,35° E18,63° (Gdańsk)

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


Masz
  1. <?php
  2. ?>
w formularz_przetagi.php? (z tego co widzę index.php - jeśli tam nie masz wrzuć :-) )

Includujesz jakoś strony - czy jak ?


po drugie to nic sie nie dzieje nawet jak podam login i pass - musisz "odświeżyć" stronę :-)

Ten post edytował b4x 4.05.2008, 14:56:24


--------------------
Go to the top of the page
+Quote Post
fran1o
post 4.05.2008, 14:57:39
Post #6





Grupa: Zarejestrowani
Postów: 65
Pomógł: 2
Dołączył: 15.04.2008

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


jak wywale session_start(); to nie ma tego błędu
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Program Files\WebServ\httpd-users\test2\formularz_przetagi.php:1) in C:\Program Files\WebServ\httpd-users\test2\index.php on line 3

ale po odswiezeniu tez sie nic nie dzieje

Ten post edytował fran1o 4.05.2008, 14:59:49
Go to the top of the page
+Quote Post
b4x
post 4.05.2008, 14:58:28
Post #7





Grupa: Zarejestrowani
Postów: 658
Pomógł: 95
Dołączył: 20.12.2005
Skąd: N54,35° E18,63° (Gdańsk)

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


Tak tak wiem - możesz wrzucić tutaj swój index.php ?


--------------------
Go to the top of the page
+Quote Post
fran1o
post 4.05.2008, 15:01:15
Post #8





Grupa: Zarejestrowani
Postów: 65
Pomógł: 2
Dołączył: 15.04.2008

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


index.php to jest ten plik co podalem na poczatku... jest narazie tylko 1 plik

Ten post edytował fran1o 4.05.2008, 15:01:41
Go to the top of the page
+Quote Post
b4x
post 4.05.2008, 15:03:56
Post #9





Grupa: Zarejestrowani
Postów: 658
Pomógł: 95
Dołączył: 20.12.2005
Skąd: N54,35° E18,63° (Gdańsk)

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


Cytat(fran1o @ 4.05.2008, 13:57:39 ) *
jak wywale session_start(); to nie ma tego błędu
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Program Files\WebServ\httpd-users\test2\formularz_przetagi.php:1) in C:\Program Files\WebServ\httpd-users\test2\index.php on line 3

ale po odswiezeniu tez sie nic nie dzieje

- Jeśli wywalisz session_start() - to logowanie nie zadziała ;-) bo sesji nie będzie.

formularz_przetagi.php - a co tam masz ? - masz jakieś nagłówki typu meta, title ?


--------------------
Go to the top of the page
+Quote Post
fran1o
post 4.05.2008, 15:10:54
Post #10





Grupa: Zarejestrowani
Postów: 65
Pomógł: 2
Dołączył: 15.04.2008

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


plik index.php
  1. <?php
  2. ?>
  3. <html>
  4. <head>
  5. <title>Test</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  7. <LINK href="style.css" rel=stylesheet type=text/css>
  8.  
  9. </head>
  10. <body bgcolor="#E0E1D9"><center>
  11.  
  12. <?php
  13. $mysql_host = "localhost";
  14. $mysql_login = "root";
  15. $mysql_pass = "";
  16. $mysql_baza = "baza2";
  17. $mysql_tabela = "users";
  18.  
  19. //********************************************************************************
  20. *****************************************************
  21. //********************************** Wylogowanie i zalogowanie z ustaleniem sesji 
    ******************************************
  22. //********************************************************************************
  23. *****************************************************
  24.  
  25. $users_login = $_POST['login'];
  26. $users_pass = $_POST['haslo'];
  27.  
  28. if($_GET['login']=="koniec") { //wylogowanie
  29. sesion_destroy();
  30. }
  31.  else if($users_login<>"" and $users_pass<>"") {
  32.  //$users_pass = md5($users_pass);
  33.  if($baza = mysql_connect($mysql_host, $mysql_login, $mysql_haslo)) {
  34. if(mysql_select_db($mysql_baza)) {
  35. $wynik = mysql_query("SELECT * FROM $mysql_tabela WHERE users_login='$users_login' and users_pass='$users_pass'") or die(mysql_error());
  36.  if(mysql_num_rows($wynik)==1) {
  37.  $dane = mysql_fetch_array($wynik);
  38.  $_SESSION['zalogowany']="tak";
  39.  $_SESSION['login']=$dane['login'];
  40.  
  41.  }
  42. } else echo "Nie można się połączyć z bazą";
  43. mysql_close($baza);
  44. }
  45. }
  46.  
  47. //********************************************************************************
  48. *****************************************************
  49. //********************************** Panel formularza do zalogowania i wylogowania
     ***************************************
  50. //********************************************************************************
  51. *****************************************************
  52.  
  53. if($_SESSION['zalogowany']=="tak") {
  54. echo "<p>Witaj <b>".$_SESSION['login']."</b></p>";
  55. echo "<br><a href=\"index.php?login=koniec\">Wyloguj się</a>";
  56. }
  57. else{
  58. echo <<<KONIEC
  59. <form action="index.php" method="post">
  60. <table>
  61. <tr>
  62. <td>Login:</td>
  63. <td><input type="text" name="login" /></td>
  64. </tr>
  65. <tr>
  66. <td>Haslo:</td>
  67. <td><input type="password" name="haslo" /></td>
  68. </tr>
  69. <tr>
  70. <td colspan="2" align="center">
  71. <input type="submit" value="zaloguj" /> 
  72. </td>
  73. </tr>
  74. </table>
  75. KONIEC;
  76.  
  77. }
  78. if($_SESSION['zalogowany']=="tak") {
  79. echo "<p>Tekst widzi osoba zalogowana</p>";
  80. }
  81.  
  82. ?>
  83. </body>
  84. </html>


logowanie dziala zapomialem ze haslo mialem szyfrowane...
ale nadal mam ten blad sesji
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Program Files\WebServ\httpd-users\test2\index.php:1) in C:\Program Files\WebServ\httpd-users\test2\index.php on line 3

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Program Files\WebServ\httpd-users\test2\index.php:1) in C:\Program Files\WebServ\httpd-users\test2\index.php on line 3
Go to the top of the page
+Quote Post
webdice
post 4.05.2008, 15:13:03
Post #11


Developer


Grupa: Moderatorzy
Postów: 3 045
Pomógł: 290
Dołączył: 20.01.2007




Było na tym forum setki razy co oznacz ten błąd i jak go wyeliminować, szukaj.

Temat zamykam.
Go to the top of the page
+Quote Post

Closed 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.07.2025 - 18:18