060_VCW_606 Posted April 17, 2009 Share Posted April 17, 2009 I'm trying to program a small system on my site revolving around the number count generated by a Perl script and output into a single-numbered text file. I'm using cookies; throughout the site (which is in PHP; the Perl part is not important in this matter), the computer compares the value in the cookie and the value on the text file to decide what to show: <?php $record = $HTTP_COOKIE_VARS["record"]; $file = "http://vcw.vali-ent.com/roleplays/count.txt"; $count = fopen($file, 'r'); $data = fread($count, 5); fclose($count); if (isset($_COOKIE['record'])){ if ($record > $data){ print("NEW!"); } else { print("No New"); } } else { print("Not Set"); } ?> My plan is to have the number update on a certain page using an iframe. And that the iframe only contains this snipet of code: <?php $file = "http://vcw.vali-ent.com/roleplays/count.txt"; $count = fopen($file, 'r'); $data = fread($count, 5); fclose($count); setcookie("record",$data,time()+604800); ?> The only problem is that the second portion of code doesn't work. Does anyone know what I'm doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/154497-solved-what-am-i-doing-wrong/ Share on other sites More sharing options...
Daniel0 Posted April 17, 2009 Share Posted April 17, 2009 Define "doesn't work". Also, throw out your book and buy a new one. $HTTP_COOKIE_VARS has been deprecated for a loooong time. Quote Link to comment https://forums.phpfreaks.com/topic/154497-solved-what-am-i-doing-wrong/#findComment-812358 Share on other sites More sharing options...
060_VCW_606 Posted April 17, 2009 Author Share Posted April 17, 2009 Execution of the second snipet returns this: Warning: Cannot modify header information - headers already sent by (output started at /home/valicom/public_html/test/boardinclude.php:1) in /home/valicom/public_html/test/boardinclude.php on line 6 Quote Link to comment https://forums.phpfreaks.com/topic/154497-solved-what-am-i-doing-wrong/#findComment-812614 Share on other sites More sharing options...
ober Posted April 17, 2009 Share Posted April 17, 2009 You're probably using "setcookie" after you've already sent something to the browser. That function has to be used before any HTML is written or PHP outputs anything to the page. Quote Link to comment https://forums.phpfreaks.com/topic/154497-solved-what-am-i-doing-wrong/#findComment-812618 Share on other sites More sharing options...
060_VCW_606 Posted April 17, 2009 Author Share Posted April 17, 2009 The snipet with setcookie() is the only code in the PHP file. Quote Link to comment https://forums.phpfreaks.com/topic/154497-solved-what-am-i-doing-wrong/#findComment-812620 Share on other sites More sharing options...
Daniel0 Posted April 17, 2009 Share Posted April 17, 2009 It says the output was sent on line 1. Make sure you haven't accidentally slipped in whitespace before the PHP opening tag. Quote Link to comment https://forums.phpfreaks.com/topic/154497-solved-what-am-i-doing-wrong/#findComment-812633 Share on other sites More sharing options...
060_VCW_606 Posted April 17, 2009 Author Share Posted April 17, 2009 There's no whitespace. I still have that output. Quote Link to comment https://forums.phpfreaks.com/topic/154497-solved-what-am-i-doing-wrong/#findComment-812672 Share on other sites More sharing options...
060_VCW_606 Posted April 17, 2009 Author Share Posted April 17, 2009 I figured it out, and I changed the deprecated part of the first snippet. Quote Link to comment https://forums.phpfreaks.com/topic/154497-solved-what-am-i-doing-wrong/#findComment-812723 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.