Connecting Tech Pros Worldwide Forums | Help | Site Map

Reload (refresh) page within an if statement

T. Wintershoven
Guest
 
Posts: n/a
#1: Nov 28 '06
Hi all,

Is there a simple way in php to reload a page coded within an if
statement.(see code below)
It's very important that the session stays intact.
The filename is RCStudent.php

**************** A peace of code***************************
<?php
session_start();
?>

if($_POST['ST']!='')
{
$_SESSION['nScreen']=2'';
}
elseif ($_POST['AT']!='')
{
$_SESSION['nScreen']=0'';

*** RELOAD CODE HERE ***
}

******************* End code*******************************

T.i.a.

Regards,

Tino Wintershoven.
The Netherlands.



Shelly
Guest
 
Posts: n/a
#2: Nov 28 '06

re: Reload (refresh) page within an if statement


"T. Wintershoven" <twintershoven@casema.nlwrote in message
news:raqdnVvftoLyvfHYnZ2dnUVZ8tSdnZ2d@casema.nl...
Quote:
Hi all,
>
Is there a simple way in php to reload a page coded within an if
statement.(see code below)
It's very important that the session stays intact.
The filename is RCStudent.php
>
**************** A peace of code***************************
<?php
session_start();
?>
>
if($_POST['ST']!='')
{
$_SESSION['nScreen']=2'';
}
elseif ($_POST['AT']!='')
{
$_SESSION['nScreen']=0'';
>
*** RELOAD CODE HERE ***
}
>
******************* End code*******************************
Do a header("Location: this_page_with_appropiate_parameter_passing"); ?

Shelly


T. Wintershoven
Guest
 
Posts: n/a
#3: Nov 28 '06

re: Reload (refresh) page within an if statement


Hi Shelly,

Thanks for your reaction.

When i do a header(location), i get an error message:
Warning: Cannot modify header information - headers already sent.

The header is allready sent on the second line ... session_start() ... (see
code)

Tino



"Shelly" <sheldonlg.news@asap-consult.comwrote in message
news:9AVah.4038$sf5.623@newsread4.news.pas.earthli nk.net...
Quote:
"T. Wintershoven" <twintershoven@casema.nlwrote in message
news:raqdnVvftoLyvfHYnZ2dnUVZ8tSdnZ2d@casema.nl...
Quote:
Hi all,

Is there a simple way in php to reload a page coded within an if
statement.(see code below)
It's very important that the session stays intact.
The filename is RCStudent.php

**************** A peace of code***************************
<?php
session_start();
?>

if($_POST['ST']!='')
{
$_SESSION['nScreen']=2'';
}
elseif ($_POST['AT']!='')
{
$_SESSION['nScreen']=0'';

*** RELOAD CODE HERE ***
}

******************* End code*******************************
>
Do a header("Location: this_page_with_appropiate_parameter_passing"); ?
>
Shelly
>
>

Ric
Guest
 
Posts: n/a
#4: Nov 28 '06

re: Reload (refresh) page within an if statement


Not sure exactly what kind of "reload" you are talking about?
I assume you mean the client's browser should reload at specific times:

PHP can't reload a site, the browser does a reload if instructed to,
therefore you need to tell the client's browser to reload the page, just
add:

<META HTTP-EQUIV=REFRESH CONTENT="10; URL=RCStudent.php">

to your html head. Here the page is reloaded every 10 seconds

PHP can redirect with header location like someone else just mentioned.
And a redirect works only if you haven't echoed any html before doing a:

header("Location: ....);


T. Wintershoven schrieb:
Quote:
Hi all,
>
Is there a simple way in php to reload a page coded within an if
statement.(see code below)
It's very important that the session stays intact.
The filename is RCStudent.php
>
**************** A peace of code***************************
<?php
session_start();
?>
>
if($_POST['ST']!='')
{
$_SESSION['nScreen']=2'';
}
elseif ($_POST['AT']!='')
{
$_SESSION['nScreen']=0'';
>
*** RELOAD CODE HERE ***
}
>
******************* End code*******************************
>
T.i.a.
>
Regards,
>
Tino Wintershoven.
The Netherlands.
>
>
Christoph Burschka
Guest
 
Posts: n/a
#5: Nov 28 '06

re: Reload (refresh) page within an if statement


You can't send a Location header after sending cookies (which
session_start() does).

So you either need to find a way to reload without starting a session,
or you need to print a <metarefresh tag into the page to reload it...


T. Wintershoven schrieb:
Quote:
Hi Shelly,
>
Thanks for your reaction.
>
When i do a header(location), i get an error message:
Warning: Cannot modify header information - headers already sent.
>
The header is allready sent on the second line ... session_start() ... (see
code)
>
Tino
>
>
>
"Shelly" <sheldonlg.news@asap-consult.comwrote in message
news:9AVah.4038$sf5.623@newsread4.news.pas.earthli nk.net...
>
Quote:
>>"T. Wintershoven" <twintershoven@casema.nlwrote in message
>>news:raqdnVvftoLyvfHYnZ2dnUVZ8tSdnZ2d@casema.nl. ..
>>
Quote:
>>>Hi all,
>>>
>>>Is there a simple way in php to reload a page coded within an if
>>>statement.(see code below)
>>>It's very important that the session stays intact.
>>>The filename is RCStudent.php
>>>
>>>**************** A peace of code***************************
>>><?php
>> session_start();
>>>?>
>>>
>>>if($_POST['ST']!='')
>>>{
>> $_SESSION['nScreen']=2'';
>>>}
>>>elseif ($_POST['AT']!='')
>>>{
>> $_SESSION['nScreen']=0'';
>>>
>> *** RELOAD CODE HERE ***
>>>}
>>>
>>>******************* End code*******************************
>>
>>Do a header("Location: this_page_with_appropiate_parameter_passing"); ?
>>
>>Shelly
>>
>>
>
>
>
--
CB
Erwin Moller
Guest
 
Posts: n/a
#6: Nov 28 '06

re: Reload (refresh) page within an if statement


Christoph Burschka wrote:
Quote:
You can't send a Location header after sending cookies (which
session_start() does).
>
So you either need to find a way to reload without starting a session,
or you need to print a <metarefresh tag into the page to reload it...
Or you buffer the output by calling ob_start() at the start of the script.
:-)

Regards,
Erwin Moller
Quote:
>
>
T. Wintershoven schrieb:
Quote:
>Hi Shelly,
>>
>Thanks for your reaction.
>>
>When i do a header(location), i get an error message:
>Warning: Cannot modify header information - headers already sent.
>>
>The header is allready sent on the second line ... session_start() ...
>(see code)
>>
>Tino
>>
>>
>>
>"Shelly" <sheldonlg.news@asap-consult.comwrote in message
>news:9AVah.4038$sf5.623@newsread4.news.pas.earthl ink.net...
>>
Quote:
>>>"T. Wintershoven" <twintershoven@casema.nlwrote in message
>>>news:raqdnVvftoLyvfHYnZ2dnUVZ8tSdnZ2d@casema.nl ...
>>>
>>>>Hi all,
>>>>
>>>>Is there a simple way in php to reload a page coded within an if
>>>>statement.(see code below)
>>>>It's very important that the session stays intact.
>>>>The filename is RCStudent.php
>>>>
>>>>**************** A peace of code***************************
>>>><?php
>>> session_start();
>>>>?>
>>>>
>>>>if($_POST['ST']!='')
>>>>{
>>> $_SESSION['nScreen']=2'';
>>>>}
>>>>elseif ($_POST['AT']!='')
>>>>{
>>> $_SESSION['nScreen']=0'';
>>>>
>>> *** RELOAD CODE HERE ***
>>>>}
>>>>
>>>>******************* End code*******************************
>>>
>>>Do a header("Location: this_page_with_appropiate_parameter_passing"); ?
>>>
>>>Shelly
>>>
>>>
>>
>>
>>
>
--
CB
ED
Guest
 
Posts: n/a
#7: Nov 28 '06

re: Reload (refresh) page within an if statement



"Christoph Burschka" <christoph.burschka@rwth-aachen.dewrote in message
news:4t2u5rF126odiU1@mid.dfncis.de...
Quote:
You can't send a Location header after sending cookies (which
session_start() does).
>
So you either need to find a way to reload without starting a session, or
you need to print a <metarefresh tag into the page to reload it...
Um, you sure about that?
The code below works fine here:

<?php
session_start();

if (! isset($_GET['refresh'])) {
setcookie('foo','Bar');
$_SESSION['foo'] = 'Bar';
header('Location:'.$_SERVER['PHP_SELF'].'?refresh=1');
} else {
echo 'page refreshed';
echo '<br />Session foo: '.$_SESSION['foo'];
echo '<br />Cookie foo: '.$_COOKIE['foo'];
}
?>

maybe the OP is outputting something (whitespace etc) prior to the
redirection?

cheers
ED


Christoph Burschka
Guest
 
Posts: n/a
#8: Nov 28 '06

re: Reload (refresh) page within an if statement


ED wrote:
Quote:
"Christoph Burschka" <christoph.burschka@rwth-aachen.dewrote in message
news:4t2u5rF126odiU1@mid.dfncis.de...
Quote:
>You can't send a Location header after sending cookies (which
>session_start() does).
>>
>So you either need to find a way to reload without starting a session, or
>you need to print a <metarefresh tag into the page to reload it...
>
Um, you sure about that?
The code below works fine here:
>
[...]
Quote:
>

Then I remember it wrong...

Oh, right: What you can't send after a cookie is the HTTP response code - such
as "HTTP/1.1 303 See Other". The status code apparently has to be the first
header sent, while the Location header can follow after the cookies just fine.

I've never used a Location header without explicitly setting a 3xx response yet,
so that's the reason for the mix-up.

--
Christoph Burschka
Buddy
Guest
 
Posts: n/a
#9: Nov 29 '06

re: Reload (refresh) page within an if statement


You most definitely cannot use Header once you have output something to
the screen. I have had to battle that one a few times. It all depends
on where the php code is put in your page. If it has to be after
something is output (<bodytag) why not use JavaScript? If before
<bodyuse <meta>.

Christoph Burschka wrote:
Quote:
ED wrote:
Quote:
"Christoph Burschka" <christoph.burschka@rwth-aachen.dewrote in message
news:4t2u5rF126odiU1@mid.dfncis.de...
Quote:
You can't send a Location header after sending cookies (which
session_start() does).
>
So you either need to find a way to reload without starting a session, or
you need to print a <metarefresh tag into the page to reload it...
Um, you sure about that?
The code below works fine here:
[...]
Quote:
>
>
Then I remember it wrong...
>
Oh, right: What you can't send after a cookie is the HTTP response code - such
as "HTTP/1.1 303 See Other". The status code apparently has to be the first
header sent, while the Location header can follow after the cookies just fine.
>
I've never used a Location header without explicitly setting a 3xx response yet,
so that's the reason for the mix-up.
>
--
Christoph Burschka
Closed Thread