Hello everyone,
I am rather new to PHP, but I do have some (well, more then some) C++ experience.
On my site I wanted to tell the user how many new articles/blog posts/3d artworks/links there are since his/her last visit. I thought this would be handy to do with cookies.
The code I am using is this:
Explanation: I am setting a cookie named "tutorialseen", the value should be 7 (current amount of tutorials), and the time is 500 hours (thought that would be long enough...).
Then I am including header.php.
header.php contains the banner, the menu and (not working though...) the amount of new items on the webpage.
These items are stored in a simple text file, so it's easier to modify.
The source of header.php is:
This is a rather simple piece of code I guess. It outputs the amount of items on the page if the cookie is not found, else it will show how many new items there are.
Now, that's all code that matters. The problem is that I'm getting this error:
Warning: Cannot modify header information - headers already sent by (output started at /home/arnovlum/domains/arno.frih.net/public_html/tutorials.php:
in /home/arnovlum/domains/arno.frih.net/public_html/tutorials.php on line 8
Line 8 is:
That is the first time on that webpage where I use php. It's the first time anything gets done with cookies.
After that line there is the include header.php, which works, except that it think it's the first time I visited it (that's not really surprising, as there is an error in setting the cookie).
I hope you can help,
Arno
I am rather new to PHP, but I do have some (well, more then some) C++ experience.
On my site I wanted to tell the user how many new articles/blog posts/3d artworks/links there are since his/her last visit. I thought this would be handy to do with cookies.
The code I am using is this:
| Code: |
| <?php setcookie("tutorialseen", 7, time()+3600*500);?>
<?php include("header.php"); ?> |
Explanation: I am setting a cookie named "tutorialseen", the value should be 7 (current amount of tutorials), and the time is 500 hours (thought that would be long enough...).
Then I am including header.php.
header.php contains the banner, the menu and (not working though...) the amount of new items on the webpage.
These items are stored in a simple text file, so it's easier to modify.
The source of header.php is:
| Code: |
| <?php
$visited=true; $file = fopen("items.txt","r"); $currentblog = fgets($file); $currenttutorial = fgets($file); $current3d = fgets($file); $currentlink = fgets($file); if (isset($_COOKIE["3dseen"])) $artseen = $_COOKIE["3dseen"]; else $visited=false; echo "<marquee> There are " . $currenttutorial . " new tutorials, " . $current3d . " 3D artworks and " . $currentlink . " links waiting for you! </marquee>"; if (isset($_COOKIE["tutorialseen"])) $tutorialseen = $_COOKIE["tutorial"]; if (isset($_COOKIE["linkseen"])) $linkseen = $_COOKIE["linkseen"]; if($visited==true) { echo "<marquee> There are " . $currenttutorial-$tutorialseen . " new tutorials/articles, " . $current3d-$artseen . " new 3D artworks and " . $currentlink-$linkseen . " new links! </marquee>"; } ?> |
This is a rather simple piece of code I guess. It outputs the amount of items on the page if the cookie is not found, else it will show how many new items there are.
Now, that's all code that matters. The problem is that I'm getting this error:
Warning: Cannot modify header information - headers already sent by (output started at /home/arnovlum/domains/arno.frih.net/public_html/tutorials.php:
Line 8 is:
| Code: |
| <?php setcookie("tutorialseen", 7, time()+3600*500);?> |
That is the first time on that webpage where I use php. It's the first time anything gets done with cookies.
After that line there is the include header.php, which works, except that it think it's the first time I visited it (that's not really surprising, as there is an error in setting the cookie).
I hope you can help,
Arno
