473,233 Members | 1,543 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,233 software developers and data experts.

Reload (refresh) page within an if statement

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
8 6678
"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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: eric rudolph | last post by:
I am writing a photo gallery and suppose 8 photos are displayed. When the user clicks on a button under the picture, I want it to add that picture name to a "favorites" list within the session...
1
by: Cooper | last post by:
Hello, is possible to disable the reload (or update, for ie) of the a web page? If yes, what i do? Otherwise if isn't possible, what i do for to set the default value of a form when a user do a...
19
by: Darren | last post by:
I have a page that opens a popup window and within the window, some databse info is submitted and the window closes. It then refreshes the original window using window.opener.location.reload(). ...
18
by: Alan Z. Scharf | last post by:
1. I have a chain of six asynch callbacks initiated by a button, and want the page to refresh at the end of each callback to display A. Results of a SQLServer query showing cumulative running...
7
by: fh | last post by:
hello! I 've a found way to reload my page automatically every n seconde using this code Response.AppendHeader("Refresh", "4"); it works fine but I wish to do the same with only a part of my...
6
by: Rain | last post by:
Does anyone have an idea on how to programmatically force a page to reload(refresh)? Im developing a asp.net web application using C#.. any help would be nice... Thanks in advance!
2
by: ericisjusteric | last post by:
I have a page with multiple iframes and need to have the user (ie6) be able to click a button to refresh any one of the iframes - but also to click another button at the top of the page to refresh...
14
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I tried a google search but could not find anything. I am trying to cause one webpage to reload when a second web page is closed. The second webpage loads data into a session variable and when...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.