Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem with refresh

Newbie
 
Join Date: Mar 2008
Posts: 10
#1: Mar 11 '08
header("refresh: 5; $url");
i used the above code to refresh the contents of a page every 5 seconds.
but i got the following errosr
Warning: Cannot modify header information - headers already sent by (output started at c:\rss\magpie_simple_2.php:3) in c:\rss\magpie_simple_2.php on line 86

so i added these two lines
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

even after that am getting the same warning for the above code.

pls help.its important
Member
 
Join Date: Nov 2007
Location: Russia, Saint-Petersburg
Posts: 82
#2: Mar 11 '08

re: Problem with refresh


You should send headers before any other information to output.
Make sure your script has no output before sending headers. It could be spaces, html-tags even php-errors.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#3: Mar 11 '08

re: Problem with refresh


On line 3 of magpie_simple_2.php you have output something to the browser.
Post your code and we'll have a look see :)
Newbie
 
Join Date: Mar 2008
Posts: 10
#4: Mar 12 '08

re: Problem with refresh


Quote:

Originally Posted by markusn00b

On line 3 of magpie_simple_2.php you have output something to the browser.
Post your code and we'll have a look see :)

Actually I have a widget inside which Im displaying the o/p from the php script which worked good for static case and giving this error when I tried to make it dynmic by refreshing.On line 3 I ve defined the style of the widget.

code snippets:
<html>
<head>
<style>--- line no : 3
.widget{
width: 300;
min-height: 50px;
border: 1px solid #CACACA;
background-color: #FFFFFF;
}
.....
.....
....
<body>
<div id='widget1' class='widget'.....
......
......
<?php
if($_GET['var'])
{
$var = $_REQUEST['var'];
}
$url = "http://rss/magpierss/$var.xml";
define('MAGPIE_DIR', 'c:\\rss\\magpierss\\');
require_once(MAGPIE_DIR.'rss_fetch.inc');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("refresh: 5; $url");
...
....
.....
?>
</div>
</body>
</html>


Need help ASAP
Member
 
Join Date: Nov 2007
Location: Russia, Saint-Petersburg
Posts: 82
#5: Mar 12 '08

re: Problem with refresh


susee, headers can not be sent after any HTML code. Do you understand it?
Newbie
 
Join Date: Mar 2008
Posts: 10
#6: Mar 12 '08

re: Problem with refresh


Quote:

Originally Posted by satas

susee, headers can not be sent after any HTML code. Do you understand it?

oh thank u....
then how can i refresh the content is there any other way of doing it apart from hearder()?
Member
 
Join Date: Nov 2007
Location: Russia, Saint-Petersburg
Posts: 82
#7: Mar 12 '08

re: Problem with refresh


Try this
[PHP]<?php
if($_GET['var'])
{
$var = $_REQUEST['var'];
}
$url = "http://rss/magpierss/$var.xml";
define('MAGPIE_DIR', 'c:\\rss\\magpierss\\');

//hope this file has no output in the bowser
require_once(MAGPIE_DIR.'rss_fetch.inc');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("refresh: 5; $url");
...
?>
<html>
<!- html code here-->

<?php
// php code here
.....
?>
<!- html code here-->
</html>
[/PHP]
Newbie
 
Join Date: Mar 2008
Location: Hyderabad
Posts: 17
#8: Mar 12 '08

re: Problem with refresh


Quote:

Originally Posted by susee

header("refresh: 5; $url");
i used the above code to refresh the contents of a page every 5 seconds.
but i got the following errosr
Warning: Cannot modify header information - headers already sent by (output started at c:\rss\magpie_simple_2.php:3) in c:\rss\magpie_simple_2.php on line 86

so i added these two lines
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

even after that am getting the same warning for the above code.

pls help.its important

hello, just put this code
[PHP] error_reporting(0);[/PHP]
on the first line and give a shot.hope it will be solved?
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#9: Mar 12 '08

re: Problem with refresh


Hello, susee and welcome to TSDN!

As has been mentioned before (possibly in a somewhat harsh tone - satas) headers are required to be sent before anything is output to the browser. It's simple to abide by once you understand.

Anyway, is it paramount that the php be refreshed or do you just want the html/css/javascript/widget to be refreshed?

If the last one is the case, have a look at META tags. There's a useful one that refreshes the page on any given amount of time!

[html]
<META
HTTP-EQUIV="refresh"
content="2;
URL=http://www.yoursite.com/newpage.htm">
[/html]
Content: Timer for refreshing.
URL: This is self explanatory :P

Hope this helps!
Newbie
 
Join Date: Mar 2008
Posts: 10
#10: Mar 20 '08

re: Problem with refresh


Quote:

Originally Posted by markusn00b

Hello, susee and welcome to TSDN!

As has been mentioned before (possibly in a somewhat harsh tone - satas) headers are required to be sent before anything is output to the browser. It's simple to abide by once you understand.

Anyway, is it paramount that the php be refreshed or do you just want the html/css/javascript/widget to be refreshed?

If the last one is the case, have a look at META tags. There's a useful one that refreshes the page on any given amount of time!

[html]
<META
HTTP-EQUIV="refresh"
content="2;
URL=http://www.yoursite.com/newpage.htm">
[/html]
Content: Timer for refreshing.
URL: This is self explanatory :P

Hope this helps!

Thanks for your reply markusn00b but as I din turn back to office for few days I could not continue..you have caught my exact issue... I need to erfresh my php part not jus the page.I have to call the fetch rss () every 5 seconds.

Thanks in advance...
Susee
Newbie
 
Join Date: Mar 2008
Posts: 10
#11: Mar 21 '08

re: Problem with refresh


Is there any other way to refresh? I mean other than this header refresh which may help refresh my php part alone?
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#12: Mar 21 '08

re: Problem with refresh


Hey susee! Sorry for the late reply!

You can still use the header refresh without problems (and if you want to refresh the page server-side you HAVE to do it with the header refresh).

You should take a look at satas' post (#7) just up there ^

If you need anymore help, let us know.

Regards, markus.
Newbie
 
Join Date: Mar 2008
Posts: 10
#13: Mar 25 '08

re: Problem with refresh


Quote:

Originally Posted by markusn00b

Hey susee! Sorry for the late reply!

You can still use the header refresh without problems (and if you want to refresh the page server-side you HAVE to do it with the header refresh).

You should take a look at satas' post (#7) just up there ^

If you need anymore help, let us know.

Regards, markus.

I ve tried satas' idea already, but if i do so my page will display the content in an unpreffered manner. I want to display the HTML widget inside which I have to display the output form the PHP part.Help me out to do this.
Reply