Thauwa Posted December 25, 2010 Share Posted December 25, 2010 :'( Hey guys! Merry Christmas!!!! Here's my problem. I have a script where I use the code include("pagerefresh.php"); where pagerefresh.php is <?php $page = $_SERVER['PHP_SELF']; $sec = "0"; header("Refresh: $sec; url=$page"); ?> I use the include function several times on the page and everything's cool with it. But once I put this: <html> <head> <title>Title</title> <script type="text/javascript"> <?php some mysql function include("timecounter.js"); ?> </script> </head> in the page, the following error pops out whenever I use some of the form functions in the page. I read the php.net manuals and discovered that the include part should come before Warning: Cannot modify header information - headers already sent by (output started at D:\Hosting\rrr\html\rrr\rrr\rrr.php:191) in D:\Hosting\rrr\html\rrr\rrr\pagerefresh.php on line 4 Oh, and I also put the javascript code directly into the page, without the include function, the same results pop out. :/ . Though I suspect that it is immaterial here, the javascript code is: var month = '<?php echo "$cmonth"; ?>'; // 1 through 12 or '*' within the next month, '0' for the current month m var day = '<?php echo "$cday"; ?>'; // day of month or + day offset d var dow = 0; // day of week sun=1 sat=7 or 0 for whatever day it falls on var hour = '<?php echo "$chour"; ?>'; // 0 through 23 for the hour of the day H var min = '<?php echo "$cminute"; ?>'; // 0 through 59 for minutes after the hour i var tz = -7; // offset in hours from UTC to your timezone var lab = 'cd'; // id of the entry on the page where the counter is to be inserted function start() {displayCountdown(setCountdown(month,day,hour,min,tz),lab);} loaded(lab,start); // Countdown Javascript // copyright 20th April 2005, 1st November 2009 by Stephen Chapman // permission to use this Javascript on your web page is granted // provided that all of the code in this script (including these // comments) is used without any alteration // you may change the start function if required var pageLoaded = 0; window.onload = function() {pageLoaded = 1;} function loaded(i,f) {if (document.getElementById && document.getElementById(i) != null) f(); else if (!pageLoaded) setTimeout('loaded(\''+i+'\','+f+')',100); } function setCountdown(month,day,hour,min,tz) {var m = month; if (month=='*') m = 0; var c = setC(m,day,hour,tz); if (month == '*' && c < 0) c = setC('*',day,hour,tz); return c;} function setC(month,day,hour,tz) {var toDate = new Date();if (day.substr(0,1) == '+') {var day1 = parseInt(day.substr(1));toDate.setDate(toDate.getDate()+day1);} else{toDate.setDate(day);}if (month == '*')toDate.setMonth(toDate.getMonth() + 1);else if (month > 0) { if (month <= toDate.getMonth())toDate.setFullYear(toDate.getFullYear() + 1);toDate.setMonth(month-1);} if (dow >0) toDate.setDate(toDate.getDate()+(dow-1-toDate.getDay())%7); toDate.setHours(hour);toDate.setMinutes(min-(tz*60));toDate.setSeconds(0);var fromDate = new Date();fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());var diffDate = new Date(0);diffDate.setMilliseconds(toDate - fromDate);return Math.floor(diffDate.valueOf()/1000);} function displayCountdown(countdn,cd) {if (countdn < 0) document.getElementById(cd).innerHTML = "Building Completed"; else {var secs = countdn % 60; if (secs < 10) secs = '0'+secs;var countdn1 = (countdn - secs) / 60;var mins = countdn1 % 60; if (mins < 10) mins = '0'+mins;countdn1 = (countdn1 - mins) / 60;var hours = countdn1 % 24;var days = (countdn1 - hours) / 24;document.getElementById(cd).innerHTML = days+' days and '+hours+' : '+mins+' : '+secs;setTimeout('displayCountdown('+(countdn-1)+',\''+cd+'\');',999);}} Thanks in advance. And Merry Christmas!!!!! Thauwa Quote Link to comment https://forums.phpfreaks.com/topic/222634-page-refresh-errors/ Share on other sites More sharing options...
Thauwa Posted December 25, 2010 Author Share Posted December 25, 2010 It seems that the javascript is reloading the page too. :/ . Does it count with php? Oh and is there any other way to have the page refreshed without using header(); and the HTML Meta Refresh? That would solve most of my problems too. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/222634-page-refresh-errors/#findComment-1151349 Share on other sites More sharing options...
PaulRyan Posted December 25, 2010 Share Posted December 25, 2010 Using the header() function will only work if there is no output before it. The following will not work... Page Content <? if($login != 'true') { include('pagerefresh.php'); } ?> Page Content The following will work... <? if($login != 'true') { include('pagerefresh.php'); } ?> Page Content Be careful using the header() function thats all I say Regards, Paul. Quote Link to comment https://forums.phpfreaks.com/topic/222634-page-refresh-errors/#findComment-1151362 Share on other sites More sharing options...
Thauwa Posted December 25, 2010 Author Share Posted December 25, 2010 Thanks PaulRyan. Very. I found that out in the php.net manual. But.... How could I proceed? It it the javascript that is the problem? ahh...... :'( Quote Link to comment https://forums.phpfreaks.com/topic/222634-page-refresh-errors/#findComment-1151369 Share on other sites More sharing options...
BlueSkyIS Posted December 25, 2010 Share Posted December 25, 2010 whatever is before header() is the problem. if it's javascript, html, blank spaces, anything. Quote Link to comment https://forums.phpfreaks.com/topic/222634-page-refresh-errors/#findComment-1151371 Share on other sites More sharing options...
blew Posted December 25, 2010 Share Posted December 25, 2010 man, try this: -- header(Location: $page Refresh: $sec); or try with die() function (i preffer to use it) die("<metta http-equiv='refresh' content='$sec;url=$page'>"); the result is the same Quote Link to comment https://forums.phpfreaks.com/topic/222634-page-refresh-errors/#findComment-1151388 Share on other sites More sharing options...
Thauwa Posted December 25, 2010 Author Share Posted December 25, 2010 Thanks, blueskyis and blew. But the page won't refresh with die("<metta http-equiv='refresh' content='$sec;url=$page'>"); :/ I believe that it is because I am not using that code in the <head> section of my page. Do correct me if I am wrong. What I really want to achieve is to reload the page once a form submits data to itself. All worked well with header(); , but after I inserted the javascript its been showing the error I mentioned above. Someone please help me. :'( . I've been working on this script for weeks and I don't won't all of it to go to waste. :-/ . I'll really appreciate more help. Thank you for now, and in advance. Quote Link to comment https://forums.phpfreaks.com/topic/222634-page-refresh-errors/#findComment-1151393 Share on other sites More sharing options...
blew Posted December 25, 2010 Share Posted December 25, 2010 Thanks, blueskyis and blew. But the page won't refresh with die("<metta http-equiv='refresh' content='$sec;url=$page'>"); :/ I believe that it is because I am not using that code in the <head> section of my page. Do correct me if I am wrong. What I really want to achieve is to reload the page once a form submits data to itself. All worked well with header(); , but after I inserted the javascript its been showing the error I mentioned above. Someone please help me. :'( . I've been working on this script for weeks and I don't won't all of it to go to waste. :-/ . I'll really appreciate more help. Thank you for now, and in advance. this PHP code must be just in the part that your PHP gonna refresh the page, after all the command u made b4... well, i dont know programming in java, so i cant help ya... im sry, but you can try posting it in the java help forums, from another sites... maybe there, sum1 can help you a little more Quote Link to comment https://forums.phpfreaks.com/topic/222634-page-refresh-errors/#findComment-1151398 Share on other sites More sharing options...
.josh Posted December 25, 2010 Share Posted December 25, 2010 meta tag name is misspelled. it's meta not metta. Quote Link to comment https://forums.phpfreaks.com/topic/222634-page-refresh-errors/#findComment-1151408 Share on other sites More sharing options...
Solar Posted December 25, 2010 Share Posted December 25, 2010 Also blank spaces in your pagerefresh.php <?php $page = $_SERVER['PHP_SELF']; $sec = "0"; header("Refresh: $sec; url=$page"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/222634-page-refresh-errors/#findComment-1151439 Share on other sites More sharing options...
Thauwa Posted December 26, 2010 Author Share Posted December 26, 2010 Oh WOW! Sorry for the confusion people! The javascript had nothing to do with the error, only the php headers. Thank you everyone, for contributing and helping me to solve my problem. Quote Link to comment https://forums.phpfreaks.com/topic/222634-page-refresh-errors/#findComment-1151489 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.