Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]setcookie- nagłówek
kujol
post
Post #1





Grupa: Zarejestrowani
Postów: 324
Pomógł: 27
Dołączył: 21.07.2013

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


Witam, mam problem ze skryptem, a dokładniej z setcookie, które nie tworzy ciastka.
Gdy skrypt jest w takiej postaci:
  1. <?php
  2. <form id="commentform" method="post" action="">
  3. <p>
  4. <input aria-required="true" tabindex="1" size="22" id="author" name="author" type="text">
  5. <input aria-required="true" tabindex="2" size="22" id="email" name="email" type="text">
  6. <textarea tabindex="4" rows="10" cols="60" id="comment-form" name="comment"></textarea> max 10 znaków
  7. <input value="Оставить комментарий" tabindex="5" id="submit" name="submit" type="submit">
  8. < /p>
  9. </form>';
  10.  
  11. if(isset($_COOKIE['komentarz1'])){
  12. setcookie('komentarz1', '1', time()+10);
  13. echo 'stworzono ciastko';
  14. }
  15.  
  16. else{
  17. setcookie('komentarz1', '2', time()+10);
  18. echo 'stworzono ciastko1';
  19. }
  20.  
  21. ?>


To wywala mi błąd:
Cytat
Warning: Cannot modify header information - headers already sent by (output started at /home/mrcash/domains/mojastrona.pl/public_html/index.php:10) in /home/mrcash/domains/mojastrona.pl/public_html/index.php on line 18


Natomiast, gdy usunę pierwszą część i zostawię go tak:

  1. <?php
  2.  
  3. if(isset($_COOKIE['komentarz1'])){
  4. setcookie('komentarz1', '1', time()+10);
  5. echo 'stworzono ciastko';
  6. }
  7.  
  8. else{
  9. setcookie('komentarz1', '2', time()+10);
  10. echo 'stworzono ciastko1';
  11. }
  12.  
  13. ?>


To wykonuję się prawidłowo. Kodowanie pliku to utf-8 bez bom. W czym może tkwić błąd?


--------------------
;)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
Damonsson
post
Post #2





Grupa: Zarejestrowani
Postów: 2 355
Pomógł: 533
Dołączył: 15.01.2010
Skąd: Bydgoszcz

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


http://phpedia.pl/wiki/Cannot_add_header_i...rs_already_sent
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: 20.08.2025 - 08:35