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 (1 - 17)
gorden
post
Post #2





Grupa: Zarejestrowani
Postów: 486
Pomógł: 101
Dołączył: 27.06.2010

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


wywal session_start z admin.php
Go to the top of the page
+Quote Post
djpotwosss
post
Post #3





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 #4





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
djpotwosss
post
Post #5





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

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


Zrobiłem tak i dalej wywala ten błąd tylko teraz na samej górze strony:(
Go to the top of the page
+Quote Post
ciekawskiii
post
Post #6





Grupa: Zarejestrowani
Postów: 467
Pomógł: 39
Dołączył: 7.11.2010
Skąd: Raz tu, raz tam

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


Wiecej niz raz wywolujesz session_start(). To Twoj skrypt wiec powinienes wiedziec co i jak, przypatrz sie na includowane pliki i znajdziesz.


--------------------
Go to the top of the page
+Quote Post
djpotwosss
post
Post #7





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

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


session_start() jest wywołany tylko raz..
Go to the top of the page
+Quote Post
ciekawskiii
post
Post #8





Grupa: Zarejestrowani
Postów: 467
Pomógł: 39
Dołączył: 7.11.2010
Skąd: Raz tu, raz tam

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


pokaz ten plik co includujesz


--------------------
Go to the top of the page
+Quote Post
djpotwosss
post
Post #9





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

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


includuje właśnie plik admin.php ...

A w pliku index.php includuje tak:

  1. <?php
  2. if($_GET['idz'] == 'administrator') include("admin.php");
  3. ?>
Go to the top of the page
+Quote Post
ciekawskiii
post
Post #10





Grupa: Zarejestrowani
Postów: 467
Pomógł: 39
Dołączył: 7.11.2010
Skąd: Raz tu, raz tam

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


to pokaz plik index


--------------------
Go to the top of the page
+Quote Post
ciekawskiii
post
Post #11





Grupa: Zarejestrowani
Postów: 467
Pomógł: 39
Dołączył: 7.11.2010
Skąd: Raz tu, raz tam

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


w index plik z session_start() includujesz w srodku strony a session powinien byc na poczatku pliku, wywal session z pliku admin i daj go do pliku index na poczatku a po drugie w includowanym pliku nie daje sie calego naglowka html, wystarczy ze masz go w index


--------------------
Go to the top of the page
+Quote Post
djpotwosss
post
Post #12





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

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


Zrobiłem tak jak mówiłeś i dalej błąd na górze strony:

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

Warning: Cannot modify header information - headers already sent by (output started at C:\WWW\index.php:1) in C:\WWW\index.php on line 4

Ten post edytował djpotwosss 26.05.2012, 20:06:07
Go to the top of the page
+Quote Post
ciekawskiii
post
Post #13





Grupa: Zarejestrowani
Postów: 467
Pomógł: 39
Dołączył: 7.11.2010
Skąd: Raz tu, raz tam

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


session_start() przed DOCTYPE!


--------------------
Go to the top of the page
+Quote Post
djpotwosss
post
Post #14





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

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


tak mam..
Go to the top of the page
+Quote Post
vifus
post
Post #15





Grupa: Zarejestrowani
Postów: 109
Pomógł: 13
Dołączył: 7.04.2012

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


spróbuj dać to na samą górę:

  1. <? include("config.php"); ?>


--------------------
Zlecenia PHP / MYSQL / JAVASCRIPT / C++ / CSS / HTML na PW
Go to the top of the page
+Quote Post
djpotwosss
post
Post #16





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

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


Dałem to na samą górę pliku index.php i dalej taki sam błąd..
Go to the top of the page
+Quote Post
PiNkOs
post
Post #17





Grupa: Zarejestrowani
Postów: 76
Pomógł: 4
Dołączył: 27.02.2009

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


Też spotkałem się kiedyś z podobnym problemem.

Pobierz Notepada i każdy plik przekoduj na UTF-8 bez BOM. (Menu Format -> Konwertuj na Format UTF-8 bez BOM)

Nie wiem czy pomoże, niemniej jednak mi kiedyś to pomogło.
Go to the top of the page
+Quote Post
djpotwosss
post
Post #18





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

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


Dzięki Ci bardzo, problem zanikłsmile.gif Od dziś będę używać tylko Notepada
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 Aktualny czas: 19.08.2025 - 15:37