Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Cannot modify header information - Nie mogę znaleźć błędu w kodzie
Forum PHP.pl > Forum > PHP
NorQ
Witam, może to być spowodowane brakiem skupienia u mnie. haha.gif Ale nie mogę znaleźć w kodzie luki która powoduje aktywność błędu:
Warning: Cannot modify header information - headers already sent by (output started at C:\WebServ\httpd\sb\index.php:19) in C:\WebServ\httpd\sb\modules\acp.php on line 68


Więc proszę was o pomoc. biggrin.gif
acp.php
  1. <div id="main">
  2. <?php
  3. // jeśli user jest zalogowany
  4. if($_SESSION['logged'])
  5. {
  6. // wyświetlamy userowi jego dane
  7. echo '<a href="logout.php">Wyloguj</a>';
  8. }
  9. // jeśli nie jest zalogowany
  10. else
  11. {
  12. // połączenie z mysql
  13. mysql_connect('localhost', 'root', '')
  14. or die('Nieudane polaczenie z baza danych...');
  15.  
  16. // wybór bazy danych
  17. or die('Nie udalo sie wybrac bazy danych...');
  18.  
  19. // sprawdzamy czy user jest już zalogowany
  20. if($_SESSION['logged']) echo 'Już jestes zalogowany!';
  21. else
  22. {
  23. // tworzymy prosty formularz
  24. echo '<form action="?p=acp" method="POST">
  25. Nick: <br />
  26. <input type="text" name="nick"><br />
  27. Hasło: <br />
  28. <input type="password" name="pass"><br />
  29. <input type="submit" name="ok" value="Zaloguj">
  30. </form>';
  31.  
  32. // jeśli zostanie naciśnięty przycisk "Zaloguj"
  33. if(isset($_POST['ok']))
  34. {
  35. $nick = $_POST['nick'];
  36. $pass = $_POST['pass'];
  37.  
  38. // sprawdzamy czy wszystkie dane zostały podane
  39. if(empty($nick) || empty($pass)) echo 'Wpisz wszystkie pola!';
  40. // jeśli tak...
  41. else
  42. {
  43. // filtrujemy dane
  44.  
  45. // sprawdzamy czy istnieje użytkownik z takim loginem i hasłem
  46. $result = mysql_query("SELECT * FROM users WHERE nick='$nick' AND pass='$pass'");
  47.  
  48. // jeśli nie istnieje
  49. if(mysql_num_rows($result)==0) echo 'Niestety podałes niepoprawne dane!';
  50. // jeśli tak...
  51. else
  52. {
  53. // dodajemy wynik zapytania do tablicy
  54. $row = mysql_fetch_array($result);
  55.  
  56. // ustawianie sesji że użytkownik jest zalogowany
  57. $_SESSION['logged'] = true;
  58.  
  59. // dodawanie do sesji id użytkownika, login oraz datę rejestracji
  60. $_SESSION['id'] = $row['id'];
  61. $_SESSION['nick'] = $row['nick'];
  62. $_SESSION['data_rejestracji'] = $row['data_rejestracji'];
  63.  
  64.  
  65. header("Location: index.php?p=acp");
  66. }
  67. }
  68. }
  69. }
  70.  
  71. // rozłączenie z bazą danych
  72. }
  73. ?>
  74. </div>
d3ut3r
przed header nie możesz wysyłać nic do przeglądarki, a wysyłasz:

  1. <div id="main">

NorQ
nic to nie dało, dodam że to jest część skryptu podstron.

Tutaj daje plik index.php :
  1. <?php
  2.  
  3. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) {
  4.  
  5. echo 'Strona nie wspiera <b>Internet Explorer</b>!';
  6.  
  7. exit();
  8.  
  9. }
  10. ?>
  11. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
  12. <head>
  13. <title>Strona Główna &raquo; Sebastian Bobrowski :: Portfolio</title>
  14. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  15. <link rel="shortcut icon" href="template/images/favicon.png" type="image/x-icon" />
  16. <link rel="stylesheet" type="text/css" href="template/css/style.css"/>
  17. <!-- LIGHTBOX POCZĄTEK -->
  18. <!-- Add jQuery library -->
  19. <script type="text/javascript" src="template/lib/jquery-1.8.2.min.js"></script>
  20.  
  21. <!-- Add mousewheel plugin (this is optional) -->
  22. <script type="text/javascript" src="template/lib/jquery.mousewheel-3.0.6.pack.js"></script>
  23.  
  24. <!-- Add fancyBox main JS and CSS files -->
  25. <script type="text/javascript" src="template/source/jquery.fancybox.js?v=2.1.2"></script>
  26. <link rel="stylesheet" type="text/css" href="template/source/jquery.fancybox.css?v=2.1.2" media="screen" />
  27.  
  28. <!-- Add Button helper (this is optional) -->
  29. <link rel="stylesheet" type="text/css" href="template/source/helpers/jquery.fancybox-buttons.css?v=1.0.5" />
  30. <script type="text/javascript" src="template/source/helpers/jquery.fancybox-buttons.js?v=1.0.5"></script>
  31.  
  32. <!-- Add Thumbnail helper (this is optional) -->
  33. <link rel="stylesheet" type="text/css" href="template/source/helpers/jquery.fancybox-thumbs.css?v=1.0.7" />
  34. <script type="text/javascript" src="template/source/helpers/jquery.fancybox-thumbs.js?v=1.0.7"></script>
  35.  
  36. <!-- Add Media helper (this is optional) -->
  37. <script type="text/javascript" src="template/source/helpers/jquery.fancybox-media.js?v=1.0.4"></script>
  38.  
  39. <script type="text/javascript">
  40. $(document).ready(function() {
  41. /*
  42. * Simple image gallery. Uses default settings
  43. */
  44.  
  45. $('.fancybox').fancybox();
  46.  
  47. /*
  48. * Different effects
  49. */
  50.  
  51. // Change title type, overlay closing speed
  52. $(".fancybox-effects-a").fancybox({
  53. helpers: {
  54. title : {
  55. type : 'outside'
  56. },
  57. overlay : {
  58. speedOut : 0
  59. }
  60. }
  61. });
  62.  
  63. // Disable opening and closing animations, change title type
  64. $(".fancybox-effects-b").fancybox({
  65. openEffect : 'none',
  66. closeEffect : 'none',
  67.  
  68. helpers : {
  69. title : {
  70. type : 'over'
  71. }
  72. }
  73. });
  74.  
  75. // Set custom style, close if clicked, change title type and overlay color
  76. $(".fancybox-effects-c").fancybox({
  77. wrapCSS : 'fancybox-custom',
  78. closeClick : true,
  79.  
  80. openEffect : 'none',
  81.  
  82. helpers : {
  83. title : {
  84. type : 'inside'
  85. },
  86. overlay : {
  87. css : {
  88. 'background' : 'rgba(238,238,238,0.85)'
  89. }
  90. }
  91. }
  92. });
  93.  
  94. // Remove padding, set opening and closing animations, close if clicked and disable overlay
  95. $(".fancybox-effects-d").fancybox({
  96. padding: 0,
  97.  
  98. openEffect : 'elastic',
  99. openSpeed : 150,
  100.  
  101. closeEffect : 'elastic',
  102. closeSpeed : 150,
  103.  
  104. closeClick : true,
  105.  
  106. helpers : {
  107. overlay : null
  108. }
  109. });
  110.  
  111. /*
  112. * Button helper. Disable animations, hide close button, change title type and content
  113. */
  114.  
  115. $('.fancybox-buttons').fancybox({
  116. openEffect : 'none',
  117. closeEffect : 'none',
  118.  
  119. prevEffect : 'none',
  120. nextEffect : 'none',
  121.  
  122. closeBtn : false,
  123.  
  124. helpers : {
  125. title : {
  126. type : 'inside'
  127. },
  128. buttons : {}
  129. },
  130.  
  131. afterLoad : function() {
  132. this.title = 'Image ' + (this.index + 1) + ' of ' + this.group.length + (this.title ? ' - ' + this.title : '');
  133. }
  134. });
  135.  
  136.  
  137. /*
  138. * Thumbnail helper. Disable animations, hide close button, arrows and slide to next gallery item if clicked
  139. */
  140.  
  141. $('.fancybox-thumbs').fancybox({
  142. prevEffect : 'none',
  143. nextEffect : 'none',
  144.  
  145. closeBtn : false,
  146. arrows : false,
  147. nextClick : true,
  148.  
  149. helpers : {
  150. thumbs : {
  151. width : 50,
  152. height : 50
  153. }
  154. }
  155. });
  156.  
  157. /*
  158. * Media helper. Group items, disable animations, hide arrows, enable media and button helpers.
  159. */
  160. $('.fancybox-media')
  161. .attr('rel', 'media-gallery')
  162. .fancybox({
  163. openEffect : 'none',
  164. closeEffect : 'none',
  165. prevEffect : 'none',
  166. nextEffect : 'none',
  167.  
  168. arrows : false,
  169. helpers : {
  170. media : {},
  171. buttons : {}
  172. }
  173. });
  174.  
  175. /*
  176. * Open manually
  177. */
  178.  
  179. $("#fancybox-manual-a").click(function() {
  180. $.fancybox.open('1_b.jpg');
  181. });
  182.  
  183. $("#fancybox-manual-b").click(function() {
  184. $.fancybox.open({
  185. href : 'iframe.html',
  186. type : 'iframe',
  187. padding : 5
  188. });
  189. });
  190.  
  191. $("#fancybox-manual-c").click(function() {
  192. $.fancybox.open([
  193. {
  194. href : '1_b.jpg',
  195. title : 'My title'
  196. }, {
  197. href : '2_b.jpg',
  198. title : '2nd title'
  199. }, {
  200. href : '3_b.jpg'
  201. }
  202. ], {
  203. helpers : {
  204. thumbs : {
  205. width: 75,
  206. height: 50
  207. }
  208. }
  209. });
  210. });
  211.  
  212.  
  213. });
  214. </script>
  215. <style type="text/css">
  216. .fancybox-custom .fancybox-skin {
  217. box-shadow: 0 0 50px #222;
  218. }
  219. </style>
  220. <!-- LIGHTBOX KONIEC -->
  221. <!--
  222. <style type="text/css">
  223. @font-face {
  224. font-family: "Myriad";
  225. src: url('socures/MyriadPro-Regular.otf');
  226. }
  227. #tooltip{
  228. position:absolute;
  229. display:none;
  230. background:#111;
  231. padding:5px;
  232. opacity: 0.50;
  233. border: 1px solid #555;
  234. color: #fff;
  235. font-family: "Myriad";
  236. font-size: 15px;
  237. border-radius: 4px;
  238. box-shadow: 0 0 5px #000;
  239. }
  240. </style>
  241. <script type="text/javascript">
  242. onl=window.onload||Function;
  243. onload=function(){
  244. onl();
  245. for(var i=0,d,D=document,E=D.documentElement,B=D.body,span;d=D.getElementsByTagName('*')[i++];){
  246. if(d.getAttribute('title')){
  247. d.old=d.title;
  248. d.removeAttribute('title');
  249. d.onmouseover=function(e){
  250. var t=this;
  251. this.t=setTimeout(
  252. function(){
  253. with(span.style){
  254. display='inline';
  255. top=t.offsetTop+t.offsetHeight+20+'px'
  256. left=t.offsetLeft+20+'px'
  257. }
  258. span.firstChild.nodeValue=t.old;
  259. }, 300)//tutaj ustawiamy zwłokę po ktrórej wyświetli się tooltip, w milisekundach!
  260. };
  261. d.onmouseout=function(){
  262. clearTimeout(this.t);
  263. span.style.display='none';
  264. }
  265. }
  266. }
  267. /* tworzenie tooltipa */
  268. span=D.createElement('span');
  269. span.id='tooltip';
  270. span.appendChild(D.createTextNode('test'));
  271. D.body.appendChild(span);
  272. }
  273. </script>
  274. -->
  275. </head>
  276. <body>
  277. <div id="head">
  278. <div class="logo"><a href="index.php"><img src="template/images/logo.png"></a></div>
  279. <div class="socials">
  280. <a href="#" target="_blank" title="Facebook.com"><img src="template/images/facebook.png"></a>
  281. <a href="#" target="_blank" title="Twitter.com"><img src="template/images/twitter.png"></a>
  282. <a class="fancybox" href="#email" title="Napisz do mnie!"><img src="template/images/email.png"></a>
  283. </div>
  284. </div>
  285. <div id="email" style="width:400px;display: none;">
  286. <div class="email">
  287. <p>Twój e-mail:<br><input type="tex"></p>
  288. <p>Temat:<br><input type="tex"></p>
  289. <p>Treść:<br><textarea></textarea></p>
  290. <p><input type="submit" value="Wyślij &raquo;"></p>
  291. </div>
  292. </div>
  293. <?php
  294. $id = $_GET['p'];
  295. if(file_exists('modules/'.$id.'.php')) {
  296. include 'modules/'.$id.'.php';
  297. } else {
  298. include 'modules/home.php';
  299. }
  300. ?>
  301. <div class="bottom"></div>
  302. <div class="footer">
  303. <div id="copy">Copyright &copy; 2012 <b>SebastianBobrowski.com</b><br>Wszelkie prawa zastrzeżone.</div><div id="copy2"><a href="?p=acp">&raquo; PANEL KONTROLNY</a></div>
  304. </div>
  305. </body>
  306. </html>
d3ut3r
Nadal wysyłasz dane do przeglądarki. Tutaj masz ładnie opisane jak możesz ten problem rozwiązać za pomocą buforowania

http://phpedia.pl/wiki/Cannot_add_header_i...rs_already_sent
abort
Sprawdź, czy w inkludowanych plikach php nie ma jakichś pustych linii po tagu zamykającym kod php...
webdice
Było tryliard razy. Proszę użyć wyszukiwarki. Zamykam.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.