473,385 Members | 1,429 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,385 software developers and data experts.

Refresh Problems

I have a page that requests an index number from the user using a
form. The submit then calls itself and a php lookup table determines
the web page required and then does a jump.

echo "<script>window.location.href='$a'</script>";

Details of the page are passed in the address line and pulled off with
POST. All works fine no problems,

However if the user hits the back button the jump is made again and
the page they are on simply reloads, as you would expect.

I tried interrogating javascript history to see where I have come from
but cannot get the location without jumping to it. If I came from
anywhere except current page then don't jump would logically seem to
work if I could do it.

Also thought about sessions but that seems like a sledgehammer to
crack a nut (also I have not had to use sessions yet so they are
untried for me).

Any other solutions or ideas gratefully accepted.

--
John

Nov 22 '05 #1
20 1664
John wrote:
I have a page that requests an index number from the user using a
form. The submit then calls itself and a php lookup table determines
the web page required and then does a jump.

echo "<script>window.location.href='$a'</script>";
why not use an include_once() instead of the redirection, which really had
been more proper if you had used header() instead of the javascript which
requires that the client has javascript enabled which some don't due security
problems and such.

http://www.php.net/manual/en/function.include-once.php
http://www.php.net/manual/en/function.header.php

However if the user hits the back button the jump is made again and
the page they are on simply reloads, as you would expect.


That is according to the rules

form_page -> redirect_page -> displayed_page

When making a back, you get back to the redirect_page and it will then
automatically redirect the user back to the displayed_page, so you need to get
rid off the redirect_page and then the include_once() will work a lot better

form_page -> displayed_page

You do things quite the same way as you did before with the javascript thing,
but don't make any outputs in the page in the question, except if you want to
generate error messages.
Instead of populating the variable $a you include the html/php page directly

eg:

switch($page_chose_from_form) {
case 1:
$a="http://example.net/mydir/myfile1.html";
break;
case 2:
$a="http://example.net/mydir/myfile2.html";
break;
case 3:
$a="http://example.net/mydir/myfile3.html";
break;
}

would be

switch($page_chose_from_form) {
case 1:
include_once('myfile1.html');
break;
case 2:
include_once('myfile2.php');
break;
case 3:
include_once('myfile3.html');
break;
default:
echo "The page don't exist!!!!";
break;
}

//Aho
Nov 22 '05 #2
Could you be a little clearer about what you want? And a bit more
specific about what you are doing?

If all you want is to be able to hit the back button and not get the
previous page, use document.location.replace()

I'm sure there are more elegant solutions to whatever you are trying to
do, though.

Ian

Nov 22 '05 #3
On 14 Nov 2005 02:05:50 -0800, "Ian B" <ia********@gmail.com> wrote:
Could you be a little clearer about what you want? And a bit more
specific about what you are doing?

If all you want is to be able to hit the back button and not get the
previous page, use document.location.replace()

I'm sure there are more elegant solutions to whatever you are trying to
do, though.


I want the user to be able to hit the back button, which could be from
one of 20 or so different pages and get back to the FORM page so that
they can type in another index if they so choose.

The problem seems to be that when the page goes back the information
from the previous entry is still there and the php thinks it is ready
to redirect which it then does. The php tests for POST (?bel_num=9999
for example) on the address line.

Hope that's clear now.

--
John
Nov 22 '05 #4
"John" wrote:
I have a page that requests an index number from the user using a
form. The submit then calls itself and a php lookup table determines
the web page required and then does a jump.

echo "<script>window.location.href='$a'</script>";
Don't use Javascript to redirect. Use a Location header instead:

<?php
header("Location: $a");
?>

If PHP refuses to do that and says something like "headers already sent",
then visit http://php.net/header and read it very carefully.
Details of the page are passed in the address line and pulled off with
POST. All works fine no problems,
Why are you using POST? Based on your description, I think GET would be more
suitable in this case. Some browsers object to being returned to a POST form
because the data is no longer valid once it has been sent. Perhaps you also
need to sit down and read RFC2626: http://www.faqs.org/rfcs/rfc2616.html
However if the user hits the back button the jump is made again and
the page they are on simply reloads, as you would expect.


That's only what I would expect from a lame Javascript redirect :-/

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/

Nov 22 '05 #5
<?php
$page='page2.php'; // set page to anything you like via your lookup
if(isset($_REQUEST['data']))
{
echo "<script>document.location.replace('$page');</script>";
exit; // Stops further pointless processing
}
echo isset($_REQUEST['data']);
?>
<html>
<head><title></title></head>
<body>
<form>
<input name="data" type="text">
<input type="submit">
</form>
</body>
</html>

Nov 22 '05 #6
John wrote:
On 14 Nov 2005 02:05:50 -0800, "Ian B" <ia********@gmail.com> wrote:
Could you be a little clearer about what you want? And a bit more
specific about what you are doing?

If all you want is to be able to hit the back button and not get the
previous page, use document.location.replace()

I'm sure there are more elegant solutions to whatever you are trying to
do, though.


I want the user to be able to hit the back button, which could be from
one of 20 or so different pages and get back to the FORM page so that
they can type in another index if they so choose.

The problem seems to be that when the page goes back the information
from the previous entry is still there and the php thinks it is ready
to redirect which it then does. The php tests for POST (?bel_num=9999
for example) on the address line.

Hope that's clear now.


Your user aren't getting back to the form page, they are getting back to the
page that was generated thanks to the results from the form page, and in your
case that page is the redirection, which leads that they are directly
redirected back to the page from where they wanted to get to the form page
with help of the backbutton on the browser. If you want to get past that
redirection, you need to hastily dubble click on the backbutton to get to the
form page. Better solutions to your problem has been already posted.
//Aho
Nov 22 '05 #7
On 14 Nov 2005 04:56:30 -0800, "Gazornenplat" <ia********@gmail.com>
wrote:
<?php
$page='page2.php'; // set page to anything you like via your lookup
if(isset($_REQUEST['data']))
{
echo "<script>document.location.replace('$page');</script>";
exit; // Stops further pointless processing
}
echo isset($_REQUEST['data']);
?>
<html>
<head><title></title></head>
<body>
<form>
<input name="data" type="text">
<input type="submit">
</form>
</body>
</html>


Thanks for the suggestions and to Ian and Gazornenplat
document.replace worked perfectly.

Curious to know what this is doing differently to windows.location
though.

--
John

Nov 22 '05 #8
John wrote:
On 14 Nov 2005 04:56:30 -0800, "Gazornenplat" <ia********@gmail.com>
wrote:
<?php
$page='page2.php'; // set page to anything you like via your lookup
if(isset($_REQUEST['data']))
{
echo "<script>document.location.replace('$page');</script>";
exit; // Stops further pointless processing
}
echo isset($_REQUEST['data']);
?>
<html>
<head><title></title></head>
<body>
<form>
<input name="data" type="text">
<input type="submit">
</form>
</body>
</html>


Thanks for the suggestions and to Ian and Gazornenplat
document.replace worked perfectly.

Curious to know what this is doing differently to windows.location
though.


IMO, Philip's suggestion(s) would be far more appropriate.

If you're using PHP, why not use it's ability to create an "official"
HTTP redirect, rather than rely on Javascript?

Using JS only leads to problems (as you've seen), and may be disabled
by the user, rendering your navigation inoperable.

That's one of the reason PHP exists! To allow you to avoid doing things
crappily and unreliably in JS, replacing it with an elegant, reliable
server-side solution.

--
Oli

Nov 22 '05 #9
On 15 Nov 2005 02:44:40 -0800, "Oli Filth" <ca***@olifilth.co.uk>
wrote:
John wrote:
On 14 Nov 2005 04:56:30 -0800, "Gazornenplat" <ia********@gmail.com>
wrote:
><?php
>$page='page2.php'; // set page to anything you like via your lookup
>if(isset($_REQUEST['data']))
>{
> echo "<script>document.location.replace('$page');</script>";
> exit; // Stops further pointless processing
>}
>echo isset($_REQUEST['data']);
>?>
><html>
><head><title></title></head>
><body>
><form>
><input name="data" type="text">
><input type="submit">
></form>
></body>
></html>


Thanks for the suggestions and to Ian and Gazornenplat
document.replace worked perfectly.

Curious to know what this is doing differently to windows.location
though.


IMO, Philip's suggestion(s) would be far more appropriate.

If you're using PHP, why not use it's ability to create an "official"
HTTP redirect, rather than rely on Javascript?

Using JS only leads to problems (as you've seen), and may be disabled
by the user, rendering your navigation inoperable.

That's one of the reason PHP exists! To allow you to avoid doing things
crappily and unreliably in JS, replacing it with an elegant, reliable
server-side solution.


Thanks Oli

It may be elegant but I get the ubiquitous 'headers already sent'
error. Javascript solves this easily.

What is the simple solution to that problem (without me having to read
a 176 page document).

Elegant is OK so long as it doesn't require reams of code. If it is
simple I will do it.

--
John

Nov 22 '05 #10
John wrote:
On 15 Nov 2005 02:44:40 -0800, "Oli Filth" <ca***@olifilth.co.uk>
wrote:
John wrote:
On 14 Nov 2005 04:56:30 -0800, "Gazornenplat" <ia********@gmail.com>
wrote:

><?php
>$page='page2.php'; // set page to anything you like via your lookup
>if(isset($_REQUEST['data']))
>{
> echo "<script>document.location.replace('$page');</script>";
> exit; // Stops further pointless processing
>}
>echo isset($_REQUEST['data']);
>?>
><html>
><head><title></title></head>
><body>
><form>
><input name="data" type="text">
><input type="submit">
></form>
></body>
></html>

Thanks for the suggestions and to Ian and Gazornenplat
document.replace worked perfectly.

Curious to know what this is doing differently to windows.location
though.

IMO, Philip's suggestion(s) would be far more appropriate.

If you're using PHP, why not use it's ability to create an "official"
HTTP redirect, rather than rely on Javascript?

Using JS only leads to problems (as you've seen), and may be disabled
by the user, rendering your navigation inoperable.

That's one of the reason PHP exists! To allow you to avoid doing things
crappily and unreliably in JS, replacing it with an elegant, reliable
server-side solution.


Thanks Oli

It may be elegant but I get the ubiquitous 'headers already sent'
error. Javascript solves this easily.


Well, JS doesn't solve this, it replaces this easily-fixable problem
with far more caveats and unfixable problems...
What is the simple solution to that problem (without me having to read
a 176 page document).


You could try going to the manual page for header(),
http://php.net/header, where you will find the "ubiquitous" solution to
this "ubiquitous" problem ;) :

" Remember that header() must be called before any actual output is
sent, either by normal HTML tags, blank lines in a file, or from PHP.
It is a very common error to read code with include(), or require(),
functions, or another file access function, and have spaces or empty
lines that are output before header() is called. The same problem
exists when using a single PHP/HTML file."

Flying by night, i.e. just typing in functions and hoping they work
without reading about how to use them, is generally not the recommended
way of programming.
--
Oli

Nov 22 '05 #11
On 15 Nov 2005 04:14:31 -0800, "Oli Filth" <ca***@olifilth.co.uk>
wrote:
John wrote:
On 15 Nov 2005 02:44:40 -0800, "Oli Filth" <ca***@olifilth.co.uk>
wrote:

<snip>
" Remember that header() must be called before any actual output is
sent, either by normal HTML tags, blank lines in a file, or from PHP.
It is a very common error to read code with include(), or require(),
functions, or another file access function, and have spaces or empty
lines that are output before header() is called. The same problem
exists when using a single PHP/HTML file."

Flying by night, i.e. just typing in functions and hoping they work
without reading about how to use them, is generally not the recommended
way of programming.


I have read that section a number of times and still don't understand
it.

OK so I use this and get the error message - headers already sent.

<?php header("Location: $page"); ?>

So what do I do now?

--
John

Nov 22 '05 #12
John wrote:
On 15 Nov 2005 04:14:31 -0800, "Oli Filth" <ca***@olifilth.co.uk>
wrote:
" Remember that header() must be called before any actual output is
sent, either by normal HTML tags, blank lines in a file, or from PHP.
It is a very common error to read code with include(), or require(),
functions, or another file access function, and have spaces or empty
lines that are output before header() is called. The same problem
exists when using a single PHP/HTML file."

I have read that section a number of times and still don't understand
it.

OK so I use this and get the error message - headers already sent.

<?php header("Location: $page"); ?>

So what do I do now?


Is there any whitespace before your <?php delimiter?

e.g.

===== VERY TOP OF FILE =====
1:
2: <?php
3: /* some code here */
4: ?>
5:
6: <?php header("Location: $page"); ?>
....

The blank lines on lines 1 and 5 would cause header not to work.

The following would also cause a problem:

===== VERY TOP OF FILE =====
1: <HTML>
2: <?php header("Location: $page"); ?>
....
--
Oli

Nov 22 '05 #13
"John" wrote:
OK so I use this and get the error message - headers already sent.

<?php header("Location: $page"); ?>

So what do I do now?


The "headers already sent" error is discussed at nauseam on thousands of
websites: http://www.googleityoumoron.com/?go=...s+already+sent

Please try to get into the habit of looking for your own answers before
pleading ignorance in places like this.

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/

Nov 22 '05 #14
> Curious to know what this is doing differently to windows.location though.

"document.location" changes the document's, er, location. History is
made!
"document replace", um, replaces the current page in the history, so
the (old) current page is, er, replaced by the new one.

Ian

Nov 22 '05 #15
On Tue, 15 Nov 2005 13:35:11 GMT, Philip Ronan
<in*****@invalid.invalid> wrote:
"John" wrote:
OK so I use this and get the error message - headers already sent.

<?php header("Location: $page"); ?>

So what do I do now?
The "headers already sent" error is discussed at nauseam on thousands of
websites: http://www.googleityoumoron.com/?go=...s+already+sent


Very clever but not very helpful.

I use google most of the time to find solutions to the problems I have
in many contexts. I come here as a last resort either because I
couldn't find the solution or didn't understand the one I was given.

I try not to test the tolerance of the people here without good cause.
Obviously its easy to overstep the mark in some cases as I seem to
have done here.

Its all very easy to be smug when you know the answers especially in
the IT industry. A little patience wouldn't go amiss. Thanks to all
those who have helped the rest of us learn something.
Please try to get into the habit of looking for your own answers before
pleading ignorance in places like this.


How do you know I haven't.

--
John
Nov 22 '05 #16
On 15 Nov 2005 05:21:35 -0800, "Oli Filth" <ca***@olifilth.co.uk>
wrote:
John wrote:
On 15 Nov 2005 04:14:31 -0800, "Oli Filth" <ca***@olifilth.co.uk>
wrote:
>" Remember that header() must be called before any actual output is
>sent, either by normal HTML tags, blank lines in a file, or from PHP.
>It is a very common error to read code with include(), or require(),
>functions, or another file access function, and have spaces or empty
>lines that are output before header() is called. The same problem
>exists when using a single PHP/HTML file."
>

I have read that section a number of times and still don't understand
it.

OK so I use this and get the error message - headers already sent.

<?php header("Location: $page"); ?>

So what do I do now?


Is there any whitespace before your <?php delimiter?

e.g.

===== VERY TOP OF FILE =====
1:
2: <?php
3: /* some code here */
4: ?>
5:
6: <?php header("Location: $page"); ?>
...

The blank lines on lines 1 and 5 would cause header not to work.

The following would also cause a problem:

===== VERY TOP OF FILE =====
1: <HTML>
2: <?php header("Location: $page"); ?>


The code is situated towards the end of a web page with the usual tags
-

<HTML>
<HEAD>
title, and other paraphernalia
includes for style sheets
</HEAD>
<BODY>
include files for menus for the page
html to capture form information
and php processing to do the jump
</HTM>

are you saying the code to do the jump must be the very first thing in
file and that's it?
--
John

Nov 22 '05 #17
On 15 Nov 2005 07:17:05 -0800, "Gazornenplat" <ia********@gmail.com>
wrote:
Curious to know what this is doing differently to windows.location though.


"document.location" changes the document's, er, location. History is
made!
"document replace", um, replaces the current page in the history, so
the (old) current page is, er, replaced by the new one.


Thanks, that makes sense now.

--
John
Nov 22 '05 #18
John said the following on 15/11/2005 19:01:
On 15 Nov 2005 05:21:35 -0800, "Oli Filth" <ca***@olifilth.co.uk>
wrote:

===== VERY TOP OF FILE =====
1:
2: <?php
3: /* some code here */
4: ?>
5:
6: <?php header("Location: $page"); ?>
...

The blank lines on lines 1 and 5 would cause header not to work.

The following would also cause a problem:

===== VERY TOP OF FILE =====
1: <HTML>
2: <?php header("Location: $page"); ?>

The code is situated towards the end of a web page with the usual tags
-

<HTML>
<HEAD>
title, and other paraphernalia
includes for style sheets
</HEAD>
<BODY>
include files for menus for the page
html to capture form information
and php processing to do the jump
</HTM>

are you saying the code to do the jump must be the very first thing in
file and that's it?


No...

header() must be used *before* all script *output*. You can do as much
PHP processing as you like, as long as nothing is output before header()
is used, e.g. echo(), print(), characters outside <?php...?>.

I'm sure this is what it pretty much said in any of the references that
Philip (rather unsubtly) pointed you toward... ;)

--
Oli
Nov 22 '05 #19
The point is that headers are sent the moment ANY page output is, er,
output. This includes spaces, newlines etc.

So if ANYTHING printable has been output, then the headers have been
sent. That is what headers are for.

If you get this error, then something has been sent to the browser and
you need to find out where. Any tag, anything at all, causes headers to
be sent and then, of course, you can't add to the headers - they have
already gone.

This IS fairly basic, and IS a common mistake, but can be a bit hard to
comprehend if you don't understand how everything works.

Ian

Nov 22 '05 #20
On Tue, 15 Nov 2005 19:12:59 GMT, Oli Filth <ca***@olifilth.co.uk>
wrote:

<snip>
are you saying the code to do the jump must be the very first thing in
file and that's it?
No...

header() must be used *before* all script *output*. You can do as much
PHP processing as you like, as long as nothing is output before header()
is used, e.g. echo(), print(), characters outside <?php...?>.


All works great, thanks for you help on this it is appreciated. I am
now beginning to see how it works.

I moved the code up and although there was some output made these were
error messages on different logical paths. So the jump was made and
returns to the form on 'back button' as required.

I am not sure how I would do it if there was some output to do but
then I can't see why that would be the case if a redirect was taking
place anyway. Cross that bridge if/when I come to it I guess.

I'm sure this is what it pretty much said in any of the references that
Philip (rather unsubtly)......


.....… and that explains the crazy situation whereby Newbies feel they
have to apologise before they start so as not to get their head bitten
off by antics like this. Fortunately I can live with this sort of
rudeness.

Thanks again

--
John
Nov 22 '05 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: plumpy321 | last post by:
Hi, I took an example from wxPython with the IE web browser and created a refresh button to automatically refresh a web page in 5 second intervals. But I notice that the memory utilization in...
1
by: Jawahar Rajan | last post by:
All, I have an ASP site that uses frames two frames. (yes I should be using include files, but we started ou using frames so we have been stuck with frames.) When I get a page expired warning...
5
by: Norbert Munkel | last post by:
Hello, Replication setup: Server 1: DB2 UDB Express 8.2 on SuSE Linux SLES 8 Instance: db2inst2 database: master Server 2: DB2 UDB Express 8.2 on SuSE Linux SLES 8 Instance: db2inst1...
2
by: juky | last post by:
Hi all, I have a loop in the thread checking for a particular service status, whenever the status changes to "stopped" a RaiseEvent is generated by thread and another function runs. At the same...
0
by: khurram.shakir | last post by:
I am developing an application, which uses .NET 2.0/WinForms and has a designer for screen layout designing. User has an option to design the layout of screen, and for that we developed our own...
1
by: Larax | last post by:
Alright, so here's the problem. I define a global variable in my script and then add methods/properties to it. Everything works great, no error in Javascript Console. But when I refresh site,...
0
by: Mirovk | last post by:
Hello Agn, 1.- Being at the a.asp I refresh the page and session variables using a JavaScript function: { simbolo = window.document.frmdir.simbolo.value;...
5
by: Ben | last post by:
Hi! I need to refresh an entire database. I can recompile SPs with sp_recompile (or DBCC FLUSHPROCINDB), and refresh views with sp_refreshView, but I cannot find any way to refresh my...
4
by: =?Utf-8?B?YmJkb2J1ZGR5?= | last post by:
I have a couple of questions, these are problems that I have experienced with IE 6 1. I have a label on a form, and sometimes when the form refreshes the label doesn't appear on the screen,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.