By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 765 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

Reload (refresh) page within an if statement

P: n/a
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.
Nov 28 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
"T. Wintershoven" <tw***********@casema.nlwrote in message
news:ra******************************@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
Nov 28 '06 #2

P: n/a
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" <sh************@asap-consult.comwrote in message
news:9A****************@newsread4.news.pas.earthli nk.net...
"T. Wintershoven" <tw***********@casema.nlwrote in message
news:ra******************************@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


Nov 28 '06 #3

P: n/a
Ric
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:
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.

Nov 28 '06 #4

P: n/a
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:
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" <sh************@asap-consult.comwrote in message
news:9A****************@newsread4.news.pas.earthli nk.net...
>>"T. Wintershoven" <tw***********@casema.nlwrote in message
news:ra******************************@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
Nov 28 '06 #5

P: n/a
Christoph Burschka wrote:
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
>

T. Wintershoven schrieb:
>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" <sh************@asap-consult.comwrote in message
news:9A****************@newsread4.news.pas.earthl ink.net...
>>>"T. Wintershoven" <tw***********@casema.nlwrote in message
news:ra******************************@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
Nov 28 '06 #6

P: n/a
ED

"Christoph Burschka" <ch****************@rwth-aachen.dewrote in message
news:4t*************@mid.dfncis.de...
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
Nov 28 '06 #7

P: n/a
ED wrote:
"Christoph Burschka" <ch****************@rwth-aachen.dewrote in message
news:4t*************@mid.dfncis.de...
>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:
[...]
>

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
Nov 28 '06 #8

P: n/a
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:
ED wrote:
"Christoph Burschka" <ch****************@rwth-aachen.dewrote in message
news:4t*************@mid.dfncis.de...
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:
[...]


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
Nov 29 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.