Passing HTTP POST information to another script - How?

This is a discussion on Passing HTTP POST information to another script - How? within the PHP Language forums, part of the PHP Programming Forums category; Hi there, I have a situation where I want to have multiple submit buttons on the same form and therefore ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-18-2005
Dave Smithz
 
Posts: n/a
Default Passing HTTP POST information to another script - How?

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


Reply With Quote
  #2 (permalink)  
Old 02-18-2005
Erwin Moller
 
Posts: n/a
Default Re: Passing HTTP POST information to another script - How?

"Dave Smithz" <SPAM FREE WORLD> wrote:

> 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


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
Reply With Quote
  #3 (permalink)  
Old 02-18-2005
Colin McKinnon
 
Posts: n/a
Default Re: Passing HTTP POST information to another script - How?

"Dave Smithz" <SPAM FREE WORLD> wrote:

> 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")
>

<snip>
Change the action of the form from javascript?

....or...

use a mini front controller which includes the relevant script?

Need more?

C.
Reply With Quote
  #4 (permalink)  
Old 02-18-2005
Dave Smithz
 
Posts: n/a
Default 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,
> >

> <snip>
> Change the action of the form from javascript?


Forgot to say I can't use Javascript - cannot risk users not having it on.

> ...or...
>
> use a mini front controller which includes the relevant script?


What is this? Does it require JavaScript?

Cheers

Dave


Reply With Quote
  #5 (permalink)  
Old 02-18-2005
Philip Ronan
 
Posts: n/a
Default Re: Passing HTTP POST information to another script - How?

Dave Smithz wrote:

> 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.


Why can't you just combine your PHP scripts (either in a single file or with
"require" statements)?

> I used:
> headers ("location:myphpscript.php")
>
> to do this.


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.

> 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).


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. :-/

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


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?

> 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.


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/


Reply With Quote
  #6 (permalink)  
Old 02-18-2005
John Dunlop
 
Posts: n/a
Default Re: Passing HTTP POST information to another script - How?

Dave Smithz wrote:

> 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.


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.

> 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.


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
Reply With Quote
  #7 (permalink)  
Old 02-19-2005
Dan Stumpus
 
Posts: n/a
Default Re: Passing HTTP POST information to another script - How?


"Dave Smithz" <SPAM FREE WORLD> wrote in message
news:4215e9d7$1@news1.homechoice.co.uk...
> 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")

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


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



Reply With Quote
  #8 (permalink)  
Old 02-19-2005
Chung Leong
 
Posts: n/a
Default Re: Passing HTTP POST information to another script - How?

"Dave Smithz" <SPAM FREE WORLD> wrote in message
news:4215e9d7$1@news1.homechoice.co.uk...
> 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.


The HTTP status code 307 is used for redirecting a POST. Only works well
with IE though.

> 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?


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']];

> 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.


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.


Reply With Quote
  #9 (permalink)  
Old 02-19-2005
Dan Stumpus
 
Posts: n/a
Default Re: Passing HTTP POST information to another script - How?

Oops! Correction:

> 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'];


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

Sorry about that...


Reply With Quote
  #10 (permalink)  
Old 02-19-2005
Philip Ronan
 
Posts: n/a
Default Re: Passing HTTP POST information to another script - How?

Chung Leong wrote:

> The HTTP status code 307 is used for redirecting a POST. Only works well
> with IE though.


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/


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:34 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0