Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] Warning: Cannot modify header information - headers already sent by..., nie lada zagadka
Jarod
post
Post #1





Grupa: Zarejestrowani
Postów: 1 190
Pomógł: 27
Dołączył: 23.04.2005

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


Piszę tego posta w tym dziale, bo sam nie wiem w czym problem - na pewno nie w php. Korzystam z apache 2.0.58 i php 5.2.0.

Mam dosyć dużą aplikację, która została tak zaprojektowana, że wszystkie headery wysyłam na samym początku, zbudowana o wzorzec MVC. Jakiś czas temu potrzebowałem kalendarz w JS i znalazłem pod adresem: http://www.kubiczek.biz/uploaded/datetimepicker.zip

Po dodaniu dwóch linijek aplikacj sypie błędami (...)headers already sent(...) Szczerze - nie wiem w czym problem..

Przy poniższym kodzie brak problemów
  1. <link rel="stylesheet" href="Css/main.css" type="text/css" />
  2. <!--[if gte IE 6]><link rel="stylesheet" href="Css/main_ie.css" type="text/css" /><![endif]-->
  3. <script type="text/javascript" src="Js/PopUp.js"></script>


Przy poniższym kodzie występuję błąd jak w tytule posta
  1. <link rel="stylesheet" href="Css/main.css" type="text/css" />
  2. <!--[if gte IE 6]><link rel="stylesheet" href="Css/main_ie.css" type="text/css" /><![endif]-->
  3. <script type="text/javascript" src="Js/PopUp.js"></script>
  4. <link rel="stylesheet" href="Css/DateTimePicker.css" type="text/css" />
  5. <script type="text/javascript" src="Js/DateTimePicker.js"></script>



Przy poniższym kodzie brak problemów
  1. <link rel="stylesheet" href="Css/main.css" type="text/css" />
  2. <script type="text/javascript" src="Js/PopUp.js"></script>
  3. <link rel="stylesheet" href="Css/DateTimePicker.css" type="text/css" />
  4. <script type="text/javascript" src="Js/DateTimePicker.js"></script>


Proszę o pomoc


EDIT:


Przeprowadziłem małe testy.. Wyniki są dla mnie zaskakujące - nie potrafię ich racjonalnie wytłumaczyć..

Brak błędu headers...
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
  3. <?php echo '<base href="http://' . $_SERVER['HTTP_HOST'] . Config::$SystemPath . '" />'; ?>
  4. <link rel="stylesheet" href="Css/main.css" type="text/css" />
  5. <link rel="stylesheet" href="Css/main1.css" type="text/css" />
  6. <link rel="stylesheet" href="Css/main2.css" type="text/css" />
  7. <link rel="stylesheet" href="Css/main3.css" type="text/css" />
  8. <link rel="stylesheet" href="Css/main4.css" type="text/css" />
  9. <link rel="stylesheet" href="Css/main5.css" type="text/css" />
  10. <link rel="stylesheet" href="Css/main6.css" type="text/css" />
  11. <link rel="stylesheet" href="Css/main7.css" type="text/css" />
  12. <link rel="stylesheet" href="Css/main8.css" type="text/css" />
  13. <link rel="stylesheet" href="Css/main9.css" type="text/css" />
  14.  
  15. <title>TransBag</title>
  16. </head>


Błąd headers already sent...
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
  3. <?php echo '<base href="http://' . $_SERVER['HTTP_HOST'] . Config::$SystemPath . '" />'; ?>
  4. <link rel="stylesheet" href="Css/main.css" type="text/css" />
  5. <link rel="stylesheet" href="Css/main1.css" type="text/css" />
  6. <link rel="stylesheet" href="Css/main2.css" type="text/css" />
  7. <link rel="stylesheet" href="Css/main3.css" type="text/css" />
  8. <link rel="stylesheet" href="Css/main4.css" type="text/css" />
  9. <link rel="stylesheet" href="Css/main5.css" type="text/css" />
  10. <link rel="stylesheet" href="Css/main6.css" type="text/css" />
  11. <link rel="stylesheet" href="Css/main7.css" type="text/css" />
  12. <link rel="stylesheet" href="Css/main8.css" type="text/css" />
  13. <link rel="stylesheet" href="Css/main9.css" type="text/css" />
  14. <link rel="stylesheet" href="Css/main10.css" type="text/css" />
  15.  
  16. <title>TransBag</title>
  17. </head>


Czy jest ograniczona ilość znaczników meta/itp, którą można zamieścić w sekcji head ?

Ten post edytował nospor 4.12.2007, 10:26:05
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Jarod
post
Post #2





Grupa: Zarejestrowani
Postów: 1 190
Pomógł: 27
Dołączył: 23.04.2005

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


(IMG:http://forum.php.pl/style_emoticons/default/smile.gif) Wiecie co? Oglądałem przed chwilką film 1408. Czytając tego posta odnoszę wrażenie że znalazłem się w takim pokoju:)
Przecież zamieściłem kod.. W swoim programie powiedzmy, że miałem błąd (już wiem gdzie) ale nie zauważyłem go, bo dopóki nie dodałem kolejnego wpisu w sekcji <head> nie wyświetlał się...

Koledzy utwórzcie plik index.php o takiej zawartości.
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <meta http-equiv="Content-Language" content="pl" />
  5. <meta name="Description" content="Description" />
  6. <meta name="Author" content="Author" />
  7. <meta name="Robots" content="all" />
  8. <meta name="Pragma" content="no-cache" />
  9. <meta name="Cache-Control" content="no-store, no-cache, must-revalidate" />
  10.  
  11. <link rel="stylesheet" href="Css/t1.css" type="text/css" />
  12. <!--[if gte IE 6]><link rel="stylesheet" href="Css/t1_ie.css" type="text/css" /><![endif]-->
  13. <link rel="stylesheet" href="Css/t2.css" type="text/css" />
  14. <link rel="stylesheet" href="Css/t3.css" type="text/css" />
  15. <link rel="stylesheet" href="Css/t4.css" type="text/css" />
  16. <link rel="stylesheet" href="Css/t5.css" type="text/css" />
  17. <link rel="stylesheet" href="Css/t6.css" type="text/css" />
  18. <link rel="stylesheet" href="Css/t7.css" type="text/css" />
  19. <link rel="stylesheet" href="Css/t8.css" type="text/css" />
  20. <link rel="stylesheet" href="Css/t9.css" type="text/css" />
  21. <link rel="stylesheet" href="Css/t10.css" type="text/css" />
  22. <link rel="stylesheet" href="Css/t11.css" type="text/css" />
  23. <link rel="stylesheet" href="Css/t12.css" type="text/css" />
  24. <link rel="stylesheet" href="Css/t13.css" type="text/css" />
  25. <link rel="stylesheet" href="Css/t14.css" type="text/css" />
  26. <link rel="stylesheet" href="Css/t15.css" type="text/css" />
  27. <link rel="stylesheet" href="Css/t16.css" type="text/css" />
  28. <link rel="stylesheet" href="Css/t17.css" type="text/css" />
  29. <link rel="stylesheet" href="Css/t18.css" type="text/css" />
  30. <link rel="stylesheet" href="Css/t19.css" type="text/css" />
  31. <link rel="stylesheet" href="Css/t20.css" type="text/css" />
  32. <link rel="stylesheet" href="Css/t21.css" type="text/css" />
  33. <link rel="stylesheet" href="Css/t22.css" type="text/css" />
  34. <link rel="stylesheet" href="Css/t23.css" type="text/css" />
  35. <link rel="stylesheet" href="Css/t24.css" type="text/css" />
  36. <link rel="stylesheet" href="Css/t25.css" type="text/css" />
  37. <link rel="stylesheet" href="Css/t26.css" type="text/css" />
  38. <link rel="stylesheet" href="Css/t27.css" type="text/css" />
  39. <link rel="stylesheet" href="Css/t28.css" type="text/css" />
  40. <link rel="stylesheet" href="Css/t29.css" type="text/css" />
  41. <link rel="stylesheet" href="Css/t30.css" type="text/css" />
  42. <link rel="stylesheet" href="Css/t31.css" type="text/css" />
  43. <link rel="stylesheet" href="Css/t32.css" type="text/css" />
  44. <link rel="stylesheet" href="Css/t33.css" type="text/css" />
  45. <link rel="stylesheet" href="Css/t34.css" type="text/css" />
  46. <link rel="stylesheet" href="Css/t35.css" type="text/css" />
  47. <link rel="stylesheet" href="Css/t36.css" type="text/css" />
  48. <link rel="stylesheet" href="Css/t37.css" type="text/css" />
  49. <link rel="stylesheet" href="Css/t38.css" type="text/css" />
  50. <link rel="stylesheet" href="Css/t39.css" type="text/css" />
  51. <link rel="stylesheet" href="Css/t40.css" type="text/css" />
  52. <link rel="stylesheet" href="Css/t41.css" type="text/css" />
  53. <link rel="stylesheet" href="Css/t42.css" type="text/css" />
  54. <link rel="stylesheet" href="Css/t43.css" type="text/css" />
  55. <link rel="stylesheet" href="Css/t44.css" type="text/css" />
  56. <link rel="stylesheet" href="Css/t45.css" type="text/css" />
  57. <link rel="stylesheet" href="Css/t46.css" type="text/css" />
  58. <link rel="stylesheet" href="Css/t47.css" type="text/css" />
  59. <link rel="stylesheet" href="Css/t48.css" type="text/css" />
  60. <link rel="stylesheet" href="Css/t49.css" type="text/css" />
  61. <link rel="stylesheet" href="Css/t50.css" type="text/css" />
  62. <link rel="stylesheet" href="Css/t51.css" type="text/css" />
  63. <link rel="stylesheet" href="Css/t52.css" type="text/css" />
  64. <link rel="stylesheet" href="Css/t53.css" type="text/css" />
  65. <link rel="stylesheet" href="Css/t54.css" type="text/css" />
  66.  
  67. <title>Tytuł</title>
  68. </head>
  69. <?php
  70. echo 'test';
  71. header('Location: http://www.google.pl');
  72. ?>
  73. </body>
  74. </html>


i odpalcie go. Powinien pojawić się błąd "Headers already sent...". I bardzo dobrze - bo próbuję wysłać nagłówek po tym, jak wyświetliłem w przeglądarce tekst... A teraz z tego samego pliku, z sekcji <head> usuńcie wpis <link rel="stylesheet" href="Css/t54.css" type="text/css" />
i odpalcie w przeglądarce jeszcze raz plik index.php. Teraz zostaniecie przekierowani na stronę googla.. Dlaczego? Przecież dalej wysyłam nagłówek po wyświetleniu w przeglądarce tekstu "test"... Chciałbym, żeby ktoś mi wytłumaczył dziwne zachowanie php, opierając się na tym przykładzie... Nie proszę o nic innego tylko o skopiowanie powyższego kodu i wklejenie go do pliku index.php i przetestowaniu.. Nie wiem jeszcze jak to wytłumaczyć.. Mam nagrać filmik?
Go to the top of the page
+Quote Post

Posty w temacie
- Jarod   [php] Warning: Cannot modify header information - headers already sent by...   24.11.2007, 20:41:53
- - webdicepl   Błąd wyskakuje bo wysyłasz coś do przeglądarki (pr...   24.11.2007, 22:22:26
|- - Jarod   Cytat(webdicepl @ 24.11.2007, 22:22:2...   24.11.2007, 22:28:09
- - webdicepl   Z treści błędu jasno wynika że coś wcześniej zosta...   24.11.2007, 22:41:24
|- - Jarod   Cytat(webdicepl @ 24.11.2007, 22:41:2...   24.11.2007, 22:51:09
- - my salsa   to musi byc wina wysylanych naglowkow przez PHP, n...   25.11.2007, 01:52:33
|- - Jarod   Cytat(my salsa @ 25.11.2007, 01:52:33...   25.11.2007, 02:01:50
- - my salsa   nie pokazujesz nam chyba calego kodu, cos tam musi...   25.11.2007, 03:11:02
|- - Jarod   Cytat(my salsa @ 25.11.2007, 03:11:02...   25.11.2007, 12:06:06
- - webdicepl   Daj zipa z wszystkim tak żeby można było to łatwo ...   25.11.2007, 12:23:59
- - SirZooro   W tym ostatnim przykładzie wywołujesz funkcję head...   25.11.2007, 13:05:49
- - Jarod   @webdicepl: Nie mogę - kod nie jest darmowy. Przet...   25.11.2007, 17:12:45
- - kevinsz   Myślę, że bez podania choćby kawałka kodu nikt Ci ...   25.11.2007, 19:20:20
- - Jarod   Wiecie co? Oglądałem przed chwilką film 1408. Czyt...   25.11.2007, 21:11:39
- - phpion.com   Hmmm mnie od razu przenosi na google, nic nie musz...   25.11.2007, 21:16:45
- - Jarod   Mam włączone wyświetlanie wszystkich błędów + E_ST...   25.11.2007, 21:49:34
- - seiya   No jaja jak berety   26.11.2007, 23:14:10
- - my salsa   ostatnio mialem podobny problem, robiac kodowanie ...   30.11.2007, 13:00:47
- - Jarod   Korzystam z eclipse no ale sprawdzę..   30.11.2007, 13:44:44
- - miska   [HTML] pobierz, plaintext <link rel="style...   4.12.2007, 10:11:32
- - nospor   @miska te spacje nie maja tu nic do gadania. Jako ...   4.12.2007, 10:22:14
- - Jarod   @nospor: Wprowadziłem ostatnio drobne zmiany w kon...   4.12.2007, 12:40:49


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: 3.10.2025 - 06:23