Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Problem z sesją po zaincludowaniu pliku
djpotwosss
post
Post #1





Grupa: Zarejestrowani
Postów: 87
Pomógł: 1
Dołączył: 3.12.2008

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


Witajcie, mam taki problem.
Gdy wpiszę w przeglądarce adres np domena.pl/admin.php to tego błędu nie ma, a gdy zaincluduje plik to pojawia sie error:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\WWW\index.php:10) in C:\WWW\admin.php on line 3

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\WWW\index.php:10) in C:\WWW\admin.php on line 3


PLik:
  1. <?php
  2. //header("Cache-Control: max-age=0");
  3. ?>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head>
  7. <title>Panel administracyjny</title>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  9. <style type="text/css" media="all">
  10. <?php if($_GET['s'] == 'zdjecia') { ?>
  11.  
  12. </style>
  13. </head>
  14. <body>
  15. <?php
  16.  
  17. if($_GET['s'] == 'wyloguj') {
  18. header("HTTP/1.1 301 Moved Permanently");
  19. header("Location:admin.php");
  20. header("Connection: close");
  21. }
  22.  
  23. if($_SESSION['logowanie'] != 'zapraszamy') {
  24. ?>
  25. <br />
  26. <div id="logowanie">Logowanie</div>
  27. <?php
  28. if($_POST['submit']) {
  29. function checkPass($user, $pass){
  30. $users = array("root" => "root"
  31. );
  32. if(array_key_exists($user, $users)){
  33. if($users[$user] == $pass){
  34. return true;
  35. }
  36. else{
  37. return false;
  38. }
  39. }
  40. else{
  41. return false;
  42. }
  43. }
  44. if(!isSet($_POST["haslo"]) || !isSet($_POST["user"])){
  45. ?>
  46. <div class="formularz_logowania">
  47. <div style="text-align: center;"><b>Błędna nazwa użytkownika lub hasło!</b></div>
  48. </div>
  49. <?php
  50. }
  51. else if(checkPass($_POST["user"], $_POST["haslo"])){
  52. $_SESSION['logowanie'] = "zapraszamy";
  53. header("HTTP/1.1 301 Moved Permanently");
  54. header("Location:admin.php");
  55. header("Connection: close");
  56. }
  57. else{
  58. ?>
  59. <div class="formularz_logowania">
  60. <div style="text-align: center;"><b>Błędna nazwa użytkownika lub hasło!</b></div>
  61. </div>
  62. <?php
  63. }
  64. }
  65. ?>
  66. <form name="logowanie" action="admin.php" method="post">
  67. <div class="formularz_logowania">
  68. <label for="user">Login: </label>
  69. <input type="text" size="35" id="user" name="user" />
  70. </div>
  71. <div class="formularz_logowania">
  72. <label for="haslo">Hasło: </label>
  73. <input type="password" name="haslo" size="35" id="haslo" />
  74. </div>
  75. <div class="formularz_logowania">
  76. <input class="zaloguj" type="submit" name="submit" value="Zaloguj się do panelu!" />
  77. </div>
  78. </form>
  79. <?php }
  80.  
  81. if($_SESSION['logowanie'] == 'zapraszamy') {
  82. include("config.php"); //config baza
  83. ?>
  84. <div id="calosc">
  85.  
  86. <div id="dane">
  87. <?php
  88. if($_GET['s'] == 'edycja') include("edytuj_podstrone.php");
  89. ?>
  90. </div>
  91. <br />
  92. </div>
  93. <?php
  94. } ?>
  95. </body>
  96. </html>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
djpotwosss
post
Post #2





Grupa: Zarejestrowani
Postów: 87
Pomógł: 1
Dołączył: 3.12.2008

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


Wywaliłem i wtedy nie działa logowanie.. Tzn nic sie nie dzieje po wpisaniu danych do logowanie..
Go to the top of the page
+Quote Post
matis95
post
Post #3





Grupa: Zarejestrowani
Postów: 17
Pomógł: 1
Dołączył: 18.12.2009

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


Cytat(djpotwosss @ 26.05.2012, 15:03:40 ) *
Wywaliłem i wtedy nie działa logowanie.. Tzn nic sie nie dzieje po wpisaniu danych do logowanie..


Jeśli dobrze paczę to plik admin.php "includujesz" do index.php. Jeśli tak jest, to na początku pliku index.php wstaw:
Kod
ob_start();
session_start();


A na koniec
Kod
ob_end_flush();


Oraz usuń wywołanie tych funkcji z pliku admin.php
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 6.10.2025 - 16:07