PDA

View Full Version : Error Redirection Question



NeedAMentor
04-19-2014, 02:39 PM
I am using this script which redirects a user to a page a 5-digit number is entered into a form box. The script works fine when the target page's filename exists on my site. If the file does not exist, the 404 error page is returned.

My question is, how do I automatically redirect the user to the previous page, or the starting page instead of the 404 error page if the input entered is anything other than a 5-digit number?

Thanks in advance.

jscheuer1
04-19-2014, 02:47 PM
Test the value of (validate) the form box before sending them off to the page. Branch from there.

If you want more help, please include a link to the page on your site that contains the problematic code or include the script in a post so we can check it out.

NeedAMentor
04-19-2014, 02:49 PM
I am using this simple script which directs a user to an html page when he enters a 5-digit number into a form box. The script works fine when the target page's filename exists on my site. If the file does not exist, the 404 error page is returned.

My question is, how do I automatically redirect the user to the previous page, or the starting page instead of the 404 error page if the input entered is anything other than a 5-digit number?

Thanks in advance.


The script:-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title></title>
<style type="text/css"></style>

<script type="text/javascript">
function init(){
df=document.forms[0];
df[0].focus();
df[1].onclick=function() {
if(df[0].value=='') {
df[0].focus();
return; }
modifiedUrl='http://www.example.com/?=event_action=yaddayaddayadda&amp;desiredname='+df[0].value;
alert(modifiedUrl);
location.href=modifiedUrl;
} }
if(window.addEventListener){
window.addEventListener('load',init,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',init);
} }
</script>

</head>
<body>

<form action="#">
<div>
<input type="text">
<input type="button" value="add text to a url">
</div>
</form>

jscheuer1
04-19-2014, 03:29 PM
Are you sure you have the 90000 or whatever it is 5 digit number pages (00000 to 99999) required for this? If so:


<script type="text/javascript">
function init(){
var df=document.forms[0];
df[0].focus();
df[1].onclick=function() {
if(!/^\d{5}$/.test(df[0].value)) { // requires a 5 digit number, otherwise:
history.go(-1); // returns to previous page (if any)
df[0].focus(); // if no previous page, focus on the text input again
return; }
// if it was a 5 digit number:
modifiedUrl='http://www.example.com/?=event_action=yaddayaddayadda&amp;desiredname='+df[0].value;
alert(modifiedUrl);
location.href=modifiedUrl;
} }
if(window.addEventListener){
window.addEventListener('load',init,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',init);
} }
</script>

If on the other hand you only want to allow a range, or certain numbers, that can be arranged. The above will allow any 5 digit number. If there aren't all that many pages, a select element that lists the only valid choices is best. Even with - say 90000 choices, you could still have a select. Instead of writing out each possible number, you could have javascript or server side code do that for you. With a select, no validation is required, because only the acceptable choices are available.

NeedAMentor
04-20-2014, 05:58 AM
First of all John, thank you for you helpfulness.

I am working on a naming system for my pages, which will always be 5-digit (eg 14001.html). It is meant to be an identificatioin number for the visitor to call up his page according to the identification number I allocate. viz. 14001-14999 (1000 file names reserved for year 2014), 15001-15999 (For 2015), and so on to the future, but probably much less files will be used in practice and not necessarily in numeric sequence. There is no requirement for strict and secure exclusion, just a simple redirection back to the previous form page for re-entry of the correct identification will do.

What is your recommendation? Thank you again for your kind help.

jscheuer1
04-20-2014, 02:19 PM
First of all, in the code you provide:



modifiedUrl='http://www.example.com/?=event_action=yaddayaddayadda&amp;desiredname='+df[0].value;

As long as that page exists for one desiredname, that page will always exist for any or all and even for no desiredname. So if that's how your setting this up, you will never have a 404, so you will need some other way to determine if the desiredname field is valid. If you are instead doing something more like so:


modifiedUrl=df[0].value + '.htm';

Then any resulting url will either exist or will not and you can redirect on the basis of whether it's there or not.

Doing it like that, if you have a server side language like PHP, a simple PHP script on an intervening page could be made to do that (check if the page is there, go there if it is, return to the form if not). Otherwise you could put the allowed numbers in a javascript on an intermediate page, or even on the same page, and have it weed them out.

Just to be sure, when you say " just a simple redirection back to the previous form page for re-entry of the correct identification will do." what page is that? Is that the page in your previous post, the one with the input for the number on it? Or is it some other page?

If it is the page with the number input on it, you shouldn't have to leave that page to know if it's a valid number, but you could. It would be a little more complicated, but probably best to remain on that page when an invalid entry is made.

Another thing of interest here is weather or not all of these pages are on the same domain. If so, that would make determining their existence easier.

NeedAMentor
04-21-2014, 11:34 AM
... Just to be sure, when you say " just a simple redirection back to the previous form page for re-entry of the correct identification will do." what page is that? Is that the page in your previous post, the one with the input for the number on it? Or is it some other page?

If it is the page with the number input on it, you shouldn't have to leave that page to know if it's a valid number, but you could. It would be a little more complicated, but probably best to remain on that page when an invalid entry is made.

Another thing of interest here is weather or not all of these pages are on the same domain. If so, that would make determining their existence easier.
Yes, I would like the same page to reappear as long as a non-existent input is entered. All the valid pages are on the same domain.

Presently, when a non-existent input is entered, an error page ("Page Not Found") appears. Then the user will need to click to go back.
Will it be possible to make that same input page always appear by default as long as the entered input does not point to a page that exists?

jscheuer1
04-21-2014, 02:50 PM
I think the only way to do that would be to have a custom server side 404 not found file for that folder that includes a slightly delayed redirect to the form page. I'm not sure how that would be done, but it could probably be worked out. But assuming the modifiedUrl is the actual page you are going to and not a script (you didn't really answer that question but seem to imply that it is a page), you could rather easily remain on the form page unless an existing page's number were entered into it:


<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title></title>
<style type="text/css"></style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>

<script type="text/javascript">
function init(){
var df=document.forms[0];
df[0].focus();
df[1].onclick=function() {
if(!/^\d{5}$/.test(df[0].value)) { // requires a 5 digit number, otherwise:
alert('Please Enter Only the Correct 5 Digit Number');
df[0].focus(); // focus on the text input again
return; }
// if it was a 5 digit number:
var modifiedUrl=df[0].value + '.htm';
$.ajax({
url: modifiedUrl,
cache: false,
success: function(){ // if the page exists:
//alert(modifiedUrl); // this alert is optional, remove it and if the right number is entered the person will go directly to the page
location.href=modifiedUrl; // go to it
},
error: function(e){ // if it's a 404 or other problem
if(e.status === 404){
alert("Page not found. Please make sure you've entered the correct 5 digit number.");
} else {
alert("That page is currently unavailable. Please make sure you've entered the correct 5 digit number or try again later.");
}
df[0].focus(); // focus on the text input again
}
});
} }
if(window.addEventListener){
window.addEventListener('load',init,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',init);
} }
</script>

</head>
<body>

<form action="#">
<div>
<input type="text">
<input type="button" value="add text to a url">
</div>
</form>

If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.

NeedAMentor
04-22-2014, 05:54 AM
I'll be working around what you have provided.
Thank you John, for your help. Much appreciated.

NeedAMentor
05-12-2014, 06:28 AM
Hi John,

I have tried your suggested code in your last post and find that it functions well when I specify a sub-directory for the 'value' field viz:-
var modifiedUrl='subdirectory/'+df[0].value + '.html'
Using this line, the requested file was found and displayed.

Then I tried removing the "sub-directory/" portion hoping that the file will be searched for in all subdirectories, but it didn't work, and an error pop-up showed.
Will it be possible to make it work that way, namely for the script to search for the file in all subdirectories? (I have many subdirectories to group the files to be searched).

Further to that, I have another related question which I will post in a subsequent thread. Thanks for your help.
Sorry for not including the link, as the page is still not established.

jscheuer1
05-13-2014, 01:07 AM
Unless you used a server side script to check, you would need to loop through all sub directories, which would need to be listed. Even using server side code, I believe it would need to be written to look in all sub directories. That is I'm not aware of any server side file locater that automatically looks in sub folders (unless they're in the path, and even then it would be tricky because that would be the server path, whereas what you would need would be the live either network, absolute, or relative path).

If you have PHP, I've worked out a method for that.

NeedAMentor
05-13-2014, 04:10 AM
Unless you used a server side script to check, you would need to loop through all sub directories, which would need to be listed...

Thanks John,

Before I try to delve into more arcane stuff like PHP, how would you suggest to modify your earlier script so it will loop through a list of specified subdirectories? That would be a good solution to what I need.

jscheuer1
05-13-2014, 05:08 AM
The order of things has changed and some things have been added. The most important thing is the array of folders (highlighted). You may have as many as you like. The more you have the longer it will take if the file's folder is at the end and when the filename qualifies and there is no file. First the immediate folder is looked at. If the file isn't there, it checks the first folder in the array, and so on for all in the array unless it finds the file. When it finds the file it switches to it.


<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title></title>
<style type="text/css"></style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>

<script type="text/javascript">
function init(){
var df=document.forms[0], folders = ['ansi', 'books'], tries;
df[0].focus();
function jaxforit(url, folder){console.log((folder || '') + url);
$.ajax({
url: (folder || '') + url,
cache: false,
success: function(){ // if the page exists:
//alert((folder || '') + url); // this alert is optional, remove it and if the right number is entered the person will go directly to the page
location.href = (folder || '') + url; // go to it
},
error: function(e){ // if it's a 404 or other problem
if((folder = folders[++tries])){
return jaxforit(url, folder + '/');
}
else if(e.status === 404){
alert("Page not found. Please make sure you've entered the correct 5 digit number.");
} else {
alert("That page is currently unavailable. Please make sure you've entered the correct 5 digit number or try again later.");
}
df[0].focus(); // focus on the text input again
}
});
}
df[1].onclick=function() {
if(!/^\d{5}$/.test(df[0].value)) { // requires a 5 digit number, otherwise:
alert('Please Enter Only the Correct 5 Digit Number');
df[0].focus(); // focus on the text input again
return; }
// if it was a 5 digit number:
var modifiedUrl=df[0].value + '.htm';
tries = -1;
jaxforit(modifiedUrl);
}
}
if(window.addEventListener){
window.addEventListener('load',init,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',init);
} }
</script>

</head>
<body>

<form action="#">
<div>
<input type="text">
<input type="button" value="add text to a url">
</div>
</form>

NeedAMentor
05-13-2014, 07:45 AM
Thank you John. That seems to work superbly when I tried it. It will be useful for a particular need.

Now I come to the related question which I promised earlier. Using the above script, as the list of subdirectories and files in them later increase substantially, it would affect the search time and thus become inefficient.

Since the first two digits of the 5-digit input specify the year (ie. '14xxx' for 2014, '15xxx' for 2015, etc), would it be possible to further alter the script so that it automatically searches only in the subdirectory in accordance with the first two digits of the input rather than every subdirectory?

The input is always 5-digits, and the subdirectories are "/14", "/15", "16", etc.

Thank you in advance.

jscheuer1
05-13-2014, 02:37 PM
Mmm, I just noticed that I left in some diagnostic code that will throw an error in some browsers. Here's the same thing without that. I also took advantage (since it's already using jQuery to perform the AJAX call(s)) of some jQuery methods to shorten and improve the code:


<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title></title>
<style type="text/css"></style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>

<script type="text/javascript">
jQuery(function($){
var df=document.forms[0], folders = ['ansi', 'books'], tries;
df[0].focus();
function jaxforit(url, folder){
$.ajax({
url: (folder || '') + url,
cache: false,
success: function(){ // if the page exists:
//alert((folder || '') + url); // this alert is optional, remove it and if the right number is entered the person will go directly to the page
location.href = (folder || '') + url; // go to it
},
error: function(e){ // if it's a 404 or other problem
if((folder = folders[++tries])){
return jaxforit(url, folder + '/');
}
else if(e.status === 404){
alert("Page not found. Please make sure you've entered the correct 5 digit number.");
} else {
alert("That page is currently unavailable. Please make sure you've entered the correct 5 digit number or try again later.");
}
df[0].focus(); // focus on the text input again
}
});
}
$(df[1]).click(function() {
if(!/^\d{5}$/.test(df[0].value)) { // requires a 5 digit number, otherwise:
alert('Please Enter Only the Correct 5 Digit Number');
df[0].focus(); // focus on the text input again
return;
}
// if it was a 5 digit number:
var modifiedUrl=df[0].value + '.htm';
tries = -1;
jaxforit(modifiedUrl);
});
$(df).submit(function(e){$(df[1]).click(); e.preventDefault();});
});

</script>

</head>
<body>

<form action="#">
<div>
<input type="text">
<input type="button" value="add text to a url">
</div>
</form>

As to your question, yes. But what is the path and filename? And is the file always in a subdirectory? Are there ever files in the same folder as the form? I think I know the answers to those questions, but before I code for it, let's make sure. I think a typical filename would be something like:

14123.htm

and a file like that (because it's name begins with 14) will always be (if it exists) in the 14 folder. So all we have check for is:

14/14123.htm

If it isn't there, it's not anywhere. And there are no files in the immediate folder that we need to look for.

Do I have all of that right?

NeedAMentor
05-13-2014, 04:05 PM
You have it all right there, John.

I will put all the files starting with "14" in the 14 folder, those starting with "15" in the 15 folder and so on. There's no need to search in the immediate folder, as long as the search for any file is done according to the corresponding folder as determined by the first two digits, which means if it's "14xxx", search in the 14 folder, if it's "15xxx", search in the 15 folder, "16xxx" in the 16 folder, and so on. Appreciate if you can suggest a script for doing this for the time being.

But I reckon since the folder 14 for instance is to contain all files accumulated in one year, would it possibly be unwieldy if there are too many files (like a few thousand) in it? What do you think?

Rwon

jscheuer1
05-13-2014, 04:43 PM
The way this search works (unlike the one where you have to list/loop through the possible sub-directories), either the file is there or it's not. The script doesn't look at each file. Rather it requests the specific file. If it's there it loads it, if it's not it alerts a (hopefully accurate) error message. It takes the same amount of time to look for the file in a folder with 1000 files as it takes to look in a folder with just a few files. Anyways, here's the new code:


<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title></title>
<style type="text/css"></style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>

<script type="text/javascript">
jQuery(function($){
var df=document.forms[0];
df[0].focus();
$(df[1]).click(function() {
if(!/^\d{5}$/.test(df[0].value)) { // requires a 5 digit number, otherwise:
alert('Please Enter Only the Correct 5 Digit Number');
df[0].focus(); // focus on the text input again
return;
}
// if it was a 5 digit number:
var modifiedUrl=df[0].value + '.htm';
$.ajax({
url: modifiedUrl.substring(0, 2) + '/' + modifiedUrl,
type: 'post',
cache: false,
success: function(){ // if the page exists:
//alert(this.url); // this alert is optional, remove it and if the right number is entered the person will go directly to the page
location.href = this.url; // go to it
},
error: function(e){ // if it's a 404 or other problem
if(e.status === 404){
alert("Page not found. Please make sure you've entered the correct 5 digit number.");
} else {
alert("That page is currently unavailable. Please make sure you've entered the correct 5 digit number or try again later.");
}
df[0].focus(); // focus on the text input again
}
});
});
$(df).submit(function(e){$(df[1]).click(); e.preventDefault();});
});

</script>

</head>
<body>

<form action="#">
<div>
<input type="text">
<input type="button" value="add text to a url">
</div>
</form>

NeedAMentor
05-14-2014, 12:51 AM
That looks wonderfully good... yummy. Thanks, John, I'll be trying it out. :)

NeedAMentor
05-19-2014, 06:53 AM
Hi John,

The script you provided works well when I tried it out. Would I need any license from you if I use it for my website in future?

jscheuer1
05-19-2014, 03:21 PM
It's barely complicated enough for that. But I'll never turn down publicity for the forum or my coding. You can add a credit:


<script type="text/javascript">
// Page Exists? Script (c)2014 John Davenport Scheuer
// as first seen in http://www.dynamicdrive.com/forums/
// username: jscheuer1 - This Notice Must Remain for Legal Use
jQuery(function($){
var df=document.forms[0];
df[0].focus();
$(df[1]).click(function() {
if(!/^\d{5}$/.test(df[0].value)) { // requires a 5 digit number, otherwise:
alert('Please Enter Only the Correct 5 Digit Number');
df[0].focus(); // focus on the text input again
return;
}
// if it was a 5 digit . . .

NeedAMentor
05-20-2014, 01:57 PM
What would be the price of a direct purchase?

jscheuer1
05-20-2014, 03:06 PM
$25.00 US to:

http://home.comcast.net/~jscheuer1/side/donate.htm

NeedAMentor
05-21-2014, 02:11 AM
Done.

Thank you for your help.

jscheuer1
05-21-2014, 03:25 AM
You're welcome. Thank you.

NeedAMentor
05-26-2014, 01:48 PM
Hi John,

I am trying to make the script work if I put the files externally on another server/domain. That is to say the folders and files are the same, but on another server instead of the same domain. The input form will still be on the existing server. Will it work as well?

jscheuer1
05-26-2014, 04:20 PM
No. AJAX follows the same origin policy. However, if there were a searching file on the server with the destination files, the form on first server could load that page on the second with a GET request. If the file were on the second server it would load, if not, the form file on the first server would reload.

NeedAMentor
05-27-2014, 01:20 AM
No. AJAX follows the same origin policy. However, if there were a searching file on the server with the destination files, the form on first server could load that page on the second with a GET request. If the file were on the second server it would load, if not, the form file on the first server would reload.

Is there a solution if I need all the searched directories and files to be on the second server/domain (which is also my domain and admin by me)? Which means to say I own two domains, with the form on the first domain and the searched directories and files are on the second domain.

If Ajax is the limiting factor, is there a solution maybe without using Ajax and such?

Thank you.

jscheuer1
05-28-2014, 02:22 PM
As I say, a searching page on the domain with the result pages could use AJAX to determine if a given page is available. A form on another domain could send a get request to the search page. However, and I didn't mention this, it would probably be better to send a post request - slightly more secure. But that can only be done if PHP is available on the domain with the result pages. Is it? The coding would be slightly easier as well. Let me know if the domain with the result pages on it has PHP available to you or not, and I will make something up for you. If you don't know if PHP is available or not on the result pages domain, let me know that, we can easily test to find out.

NeedAMentor
05-30-2014, 04:34 AM
Thanks John,

It's not hosted at the moment. If I use the method, it will of course be up to me put it on a host which supports PHP, since both the domains would be my own. But since I am a newbie with PHP, I may need time to adjust to it
.

As I say, a searching page on the domain with the result pages could use AJAX to determine if a given page is available. A form on another domain could send a get request to the search page. However, and I didn't mention this, it would probably be better to send a post request - slightly more secure. But that can only be done if PHP is available on the domain with the result pages. Is it? The coding would be slightly easier as well. Let me know if the domain with the result pages on it has PHP available to you or not, and I will make something up for you. If you don't know if PHP is available or not on the result pages domain, let me know that, we can easily test to find out.

jscheuer1
05-30-2014, 05:04 AM
If PHP is available on the domain with the result pages on it, the sending page (which doesn't need PHP), let's call it form.htm:


<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>Check Other Domain - Demo</title>
<style type="text/css"></style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>

<script type="text/javascript">
jQuery(function($){
var sp = 'http://somedomain.com/search.php', // full address to the search page
df=document.forms[0];
df[0].focus();
function submitfunc(e) {
if(!/^\d{5}$/.test(df[0].value)) { // requires a 5 digit number, otherwise:
alert('Please Enter Only the Correct 5 Digit Number');
e.preventDefault();
df[0].focus(); // focus on the text input again
return false;
}
// if it was a 5 digit number:
return true;
}
$(df).submit(submitfunc).attr('action', sp).attr('method', 'post');
$(window).unload(function(){});
});

</script>

</head>
<body>

<form action="#">
<div>
<input name="page" type="text">
<input type="submit" value="add text to a url">
</div>
</form>

And then the search.php page on the domain with PHP and the result pages:


<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
$page = isset($_POST['page'])? $_POST['page'] : '';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>Check This Domain w/PHP - Demo</title>
<style type="text/css"></style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>

<script type="text/javascript">
jQuery(function($){
var fp = 'http://originaldomain.com/form.htm', //full address to form page
m = '<?php echo $page; ?>';
if(!m){window.location.replace(fp); return;} // no query sent, go to form page
$.ajax({
url: m.substring(0, 2) + '/' + m + '.htm',
type: 'post',
cache: false,
success: function(){ // if the page exists:
//alert(this.url); // this alert is optional, remove it and if the right number is entered the person will go directly to the page
location.href = this.url; // go to it
},
error: function(e){ // if it's a 404 or other problem
if(e.status === 404){
alert("Page not found. Please make sure you've entered the correct 5 digit number.");
} else {
alert("That page is currently unavailable. Please make sure you've entered the correct 5 digit number or try again later.");
}
window.location.replace(fp); // return to form page
}
});
});

</script>

NeedAMentor
05-30-2014, 11:05 AM
Thanks John,

I will keep the codes for reference and perhaps test it later when I have another working host set up. At the moment, I am stilll grappling with trying to understand some basic PHP stuff. Meantime, I will stick to the Ajax script you've provided earlier, which is superb. Thanks again John. Much appreciated.

jscheuer1
05-31-2014, 03:03 PM
The PHP used is almost less than basic. Just 2 headers:


header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

to prevent caching of the page (in case files folks are looking for are added or removed) and code to get the posted value (ex: 14123):


$page = isset($_POST['page'])? $_POST['page'] : '';

from the sending form page and to use that value in the javascript:


m = '<?php echo $page; ?>';

The most complex part was really the spreading out of the javascript over the two pages.

If you have any questions, let me know.