Connecting Tech Pros Worldwide Help | Site Map

Passing HTTP POST information to another script - How?

Dave Smithz
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi there,

I have a situation where I want to have multiple submit buttons on the same
form and therefore want to use a redirection php script that checks the
value associated with the submit form variable to calculate which submit was
pressed and then redirects the user to another php page accordingly.

I used:
headers ("location:myphpscript.php")

to do this.

However automatically this does not pass on the information sent in the form
POST. I did start looking into reencoding the $_REQUEST into a GET string to
append to the URL, but this is a bit crude because the original form submit
uses a post and had a lot of information (some of which is also held in
$_FILES).

So is there a better way to go about this? How can I simulate a POST?

My second related question on this subject (I was going to post this
separately but it's probably better here) is whether there is a limit to the
amount of information that can be passed via an HTTP GET.
I once remember reading there is a 255 character limit to a URL address and
if this also includes the variable information after the ? this is quite
restrictive.

Kind regards

Dave


Erwin Moller
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Passing HTTP POST information to another script - How?


"Dave Smithz" <SPAM FREE WORLD> wrote:
[color=blue]
> Hi there,
>
> I have a situation where I want to have multiple submit buttons on the
> same form and therefore want to use a redirection php script that checks
> the value associated with the submit form variable to calculate which
> submit was pressed and then redirects the user to another php page
> accordingly.
>
> I used:
> headers ("location:myphpscript.php")
>
> to do this.
>
> However automatically this does not pass on the information sent in the
> form POST. I did start looking into reencoding the $_REQUEST into a GET
> string to append to the URL, but this is a bit crude because the original
> form submit uses a post and had a lot of information (some of which is
> also held in $_FILES).
>
> So is there a better way to go about this? How can I simulate a POST?
>
> My second related question on this subject (I was going to post this
> separately but it's probably better here) is whether there is a limit to
> the
> amount of information that can be passed via an HTTP GET.
> I once remember reading there is a 255 character limit to a URL address
> and if this also includes the variable information after the ? this is
> quite restrictive.
>
> Kind regards
>
> Dave[/color]

Hi Dave,

When php.net fixed their bug, look here:
http://nl2.php.net/manual/en/ref.curl.php

curl lets you mimic postings.

Regards,
Erwin Moller
Colin McKinnon
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Passing HTTP POST information to another script - How?


"Dave Smithz" <SPAM FREE WORLD> wrote:
[color=blue]
> Hi there,
>
> I have a situation where I want to have multiple submit buttons on the
> same form and therefore want to use a redirection php script that checks
> the value associated with the submit form variable to calculate which
> submit was pressed and then redirects the user to another php page
> accordingly.
>
> I used:
> headers ("location:myphpscript.php")
>[/color]
<snip>
Change the action of the form from javascript?

....or...

use a mini front controller which includes the relevant script?

Need more?

C.
Dave Smithz
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Passing HTTP POST information to another script - How?



"Colin McKinnon" <colin.deletethis@andthis.mms3.com> wrote in message
news:cv5106$o7i$1> > Hi there,[color=blue][color=green]
> >[/color]
> <snip>
> Change the action of the form from javascript?[/color]

Forgot to say I can't use Javascript - cannot risk users not having it on.
[color=blue]
> ...or...
>
> use a mini front controller which includes the relevant script?[/color]

What is this? Does it require JavaScript?

Cheers

Dave


Philip Ronan
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Passing HTTP POST information to another script - How?


Dave Smithz wrote:
[color=blue]
> Hi there,
>
> I have a situation where I want to have multiple submit buttons on the same
> form and therefore want to use a redirection php script that checks the
> value associated with the submit form variable to calculate which submit was
> pressed and then redirects the user to another php page accordingly.[/color]

Why can't you just combine your PHP scripts (either in a single file or with
"require" statements)?
[color=blue]
> I used:
> headers ("location:myphpscript.php")
>
> to do this.[/color]

By redirecting POST requests you are asking for trouble. For example, take a
look at <http://ppewww.ph.gla.ac.uk/~flavell/www/post-redirect.html>. A
simple header statement just won't work properly, even if you get the syntax
right and use an absolute URI like you're supposed to.
[color=blue]
> However automatically this does not pass on the information sent in the form
> POST. I did start looking into reencoding the $_REQUEST into a GET string to
> append to the URL, but this is a bit crude because the original form submit
> uses a post and had a lot of information (some of which is also held in
> $_FILES).[/color]

By redirecting a POST request you're asking the client's browser to re-issue
the request to a different URL. That would mean sending the file twice. I
don't think that's a good idea. :-/
[color=blue]
> So is there a better way to go about this? How can I simulate a POST?[/color]

Do all your server-side processing at the URL specified by the form's action
attribute. That's the way things are supposed to work. Or use different
forms linked to different server-side scripts.

Could you perhaps explain a bit more about what you're trying to do with
this form?
[color=blue]
> My second related question on this subject (I was going to post this
> separately but it's probably better here) is whether there is a limit to the
> amount of information that can be passed via an HTTP GET.
> I once remember reading there is a 255 character limit to a URL address and
> if this also includes the variable information after the ? this is quite
> restrictive.[/color]

I think it' more like 4096 characters, but don't take my word for it. It's
definitely a lot more than 255.

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


John Dunlop
Guest
 
Posts: n/a
#6: Jul 17 '05

re: Passing HTTP POST information to another script - How?


Dave Smithz wrote:
[color=blue]
> My second related question on this subject (I was going to post this
> separately but it's probably better here) is whether there is a limit to the
> amount of information that can be passed via an HTTP GET.[/color]

Depends.

In theory, no. The generic URI spec does not impose a limit
on the length of URIs, and the HTTP spec does not impose a
limit on the length of its URIs either. From sec. 3.2.1 of
the latter:

| The HTTP protocol does not place any /a priori/ limit on
| the length of a URI. Servers MUST be able to handle the
| URI of any resource they serve, and SHOULD be able to
| handle URIs of unbounded length if they provide GET-based
| forms that could generate such URIs. A server SHOULD
| return 414 (Request-URI Too Long) status if a URI is
| longer than the server can handle ...

http://www.ietf.org/rfc/rfc2616.txt

So an HTTP URI with a query string ten thousand characters
long, if unwieldy, accords with the interworking
specifications.

In practice, however, yes. There are implementation-
specific limits.
[color=blue]
> I once remember reading there is a 255 character limit to a URL address and
> if this also includes the variable information after the ? this is quite
> restrictive.[/color]

RFC2616 (1999) notes that older software might not support
URIs longer than 255 bytes. I should like to think that
that limit is imposed only by some archaic implementations,
the likes of which you'd seldom encounter nowadays.

Slainte!

--
Jock
Dan Stumpus
Guest
 
Posts: n/a
#7: Jul 17 '05

re: Passing HTTP POST information to another script - How?



"Dave Smithz" <SPAM FREE WORLD> wrote in message
news:4215e9d7$1@news1.homechoice.co.uk...[color=blue]
> Hi there,
>
> I have a situation where I want to have multiple submit buttons on the
> same
> form and therefore want to use a redirection php script that checks the
> value associated with the submit form variable to calculate which submit
> was
> pressed and then redirects the user to another php page accordingly.
>
> I used:
> headers ("location:myphpscript.php")[/color]
......[color=blue]
> So is there a better way to go about this? How can I simulate a POST?[/color]

You can put all kinds of data "in session".

eg,

in the script receiving the original POST:

session_start(); // should appear before *any* output in the script...
$_SESSION['posted'] = $_POST;

The above stores the entire post array in-session.
Now you can redirect to any page you want, or the user can click on a link
to a script of yours, and within that destination script you do:

session_start(); // should appear before *any* output in the script...
posted = $_SESSION['entryFormValues'];

Now the posted array is available and has the original $_POST info from the
original script.

(read up on sessions...extremely useful stuff)

-- Dan



Chung Leong
Guest
 
Posts: n/a
#8: Jul 17 '05

re: Passing HTTP POST information to another script - How?


"Dave Smithz" <SPAM FREE WORLD> wrote in message
news:4215e9d7$1@news1.homechoice.co.uk...[color=blue]
> Hi there,
>
> I have a situation where I want to have multiple submit buttons on the[/color]
same[color=blue]
> form and therefore want to use a redirection php script that checks the
> value associated with the submit form variable to calculate which submit[/color]
was[color=blue]
> pressed and then redirects the user to another php page accordingly.
>
> I used:
> headers ("location:myphpscript.php")
>
> to do this.[/color]

The HTTP status code 307 is used for redirecting a POST. Only works well
with IE though.
[color=blue]
> However automatically this does not pass on the information sent in the[/color]
form[color=blue]
> POST. I did start looking into reencoding the $_REQUEST into a GET string[/color]
to[color=blue]
> append to the URL, but this is a bit crude because the original form[/color]
submit[color=blue]
> uses a post and had a lot of information (some of which is also held in
> $_FILES).
>
> So is there a better way to go about this? How can I simulate a POST?[/color]

If session is available, you can stick the $_POST array in there:

$key = md5(serialize($_POST));
$_SESSION[$key] = $_POST;
header("Location: otherfile.php?key=$key");

then retrieve it in the other page:
$_POST = $_SESSION[$_GET['key']];
[color=blue]
> My second related question on this subject (I was going to post this
> separately but it's probably better here) is whether there is a limit to[/color]
the[color=blue]
> amount of information that can be passed via an HTTP GET.
> I once remember reading there is a 255 character limit to a URL address[/color]
and[color=blue]
> if this also includes the variable information after the ? this is quite
> restrictive.[/color]

It was a problem affecting one of the ancient browsers. Might have been IE
2, I can't remember. The browser would die from a stack overflow error when
the URL is longer than 255.


Dan Stumpus
Guest
 
Posts: n/a
#9: Jul 17 '05

re: Passing HTTP POST information to another script - How?


Oops! Correction:
[color=blue]
> You can put all kinds of data "in session".
>
> eg,
>
> in the script receiving the original POST:
>
> session_start(); // should appear before *any* output in the script...
> $_SESSION['posted'] = $_POST;
>
> The above stores the entire post array in-session.
> Now you can redirect to any page you want, or the user can click on a link
> to a script of yours, and within that destination script you do:
>
> session_start(); // should appear before *any* output in the script...
> posted = $_SESSION['entryFormValues'];[/color]

Above line should be: posted = $_SESSION['posted'];

Sorry about that...


Philip Ronan
Guest
 
Posts: n/a
#10: Jul 17 '05

re: Passing HTTP POST information to another script - How?


Chung Leong wrote:
[color=blue]
> The HTTP status code 307 is used for redirecting a POST. Only works well
> with IE though.[/color]

Actually it doesn't work well with IE at all.
See <http://ppewww.ph.gla.ac.uk/~flavell/www/post-redirect.html>

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


R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#11: Jul 17 '05

re: Passing HTTP POST information to another script - How?


Dave Smithz wrote:[color=blue]
> Hi there,
>
> I have a situation where I want to have multiple submit buttons on[/color]
the same[color=blue]
> form and therefore want to use a redirection php script that checks[/color]
the[color=blue]
> value associated with the submit form variable to calculate which[/color]
submit was[color=blue]
> pressed and then redirects the user to another php page accordingly.
>
> I used:
> headers ("location:myphpscript.php")
>
> to do this.
>
> However automatically this does not pass on the information sent in[/color]
the form[color=blue]
> POST. I did start looking into reencoding the $_REQUEST into a GET[/color]
string to[color=blue]
> append to the URL, but this is a bit crude because the original form[/color]
submit[color=blue]
> uses a post and had a lot of information (some of which is also held[/color]
in[color=blue]
> $_FILES).
>
> So is there a better way to go about this? How can I simulate a POST?[/color]

I don't know, why you have to redirect to another page. If you have
some good Form handler mechanism, you can do like this (in the same
page--even witout losing the clarity/readability/etc):

if ( $foo->isFormSubmitted($_POST, 'deposit') )
{
$foo->isValidDepositFields() and
$foo->addToDepositTable();
}
else if ( $foo->isFormSubmitted($_POST, 'withdraw') )
{
...
}

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Closed Thread