Re: How do I setup php script to return a browser page?
From: Martin Cooper (usenetspam_at_martinc.me.uk)
Date: 10/12/04
- Next message: Chung Leong: "Re: Hide URL parameters"
- Previous message: SC: "More accurate web analysis"
- In reply to: Don: "Re: How do I setup php script to return a browser page?"
- Next in thread: red: "Re: How do I setup php script to return a browser page?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 12 Oct 2004 02:30:18 +0100
<snip>
>
> Martin,
>
> I studied the script and think I understand how it works. However, the
> client-side page in my case
> is dynamically built using JS, so it isn't as simple as storing the page
> on the server as you
> suggest. I really need to submit the page's initial <form> to server A,
> along with all the page
> content via an array, have server A process the form, and rebuild (via
> print) the client-side page
> that came along, modify the embedded <form> to address server B. Then,
> when server A has finished
> processing the initial <form> it will return the initial client-side page,
> with the modified <form>.
> That modified <form> will have an onload event handler, so it will fire
> without client intervention.
> All of this happens as a result of the client clicking one and only one
> submit button.
>
> By the way, the initial <form> uploads one or more files to server A.
> And, the second <form> just
> submits some data to server B. Server B will return an appropriate
> browser page.
>
> I just don't know how to pass the client-side page to server A, via an
> <input type=hidden...> using
> an array. And, I don't know how to retrieve it in the PHP script on the
> server.
>
> What do you think?
> Don
Hi Don,
I can't think of a way to submit the complete page, but you could write
an event handler for the 'onsubmit' event in javascript that would parse the
page, gather the information you required from the page, and create a series
of post fields each containing a peice of the information.
Sorry, I'm not familiar enough with javascript to tell you exactly how, but
once you have gathered the info, embed each peice of data in a hidden field
called 'arrayXXXXX' where XXXXX is an incrimenting number. This would
arrive on the server in the _POST array. You can then parse the post array
with a foreach loop such as :-
foreach ($_POST as $key=>$value)
{
if (preg_match ("/^array([0-9\-]+)/i", $key, $matches))
{
$array[$matches[1]] = $value;
}
}
// process data here
So after this script has run, the various post elements (each having a
unique number generated by javascript) would be accessable via a standard
PHP array containing the data gathered from the webpage by the javascript.
The javascript would have to recursively parse the DOM, gathering the needed
information as it went from the document.
In the DOM, as you probably know, each HTML tag is accessable, so by
recusring through the entire page, you can build an array for the post that
contains a copy of every part of the page. By submitting these with an
incrimenting number, the foreach loop above could be used to reconstruct the
page. For the javascript side, take a look at
http://www.webreference.com/programming/javascript/definitive/chap17/6.html
for a recursive function that can traverse the entire document.
This may not be the only way, but I can't think of an easier way right now.
Martin
- Next message: Chung Leong: "Re: Hide URL parameters"
- Previous message: SC: "More accurate web analysis"
- In reply to: Don: "Re: How do I setup php script to return a browser page?"
- Next in thread: red: "Re: How do I setup php script to return a browser page?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|