Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Relocating and POSTing

0 views
Skip to first unread message

Alex Chamberlain

unread,
Jul 10, 2008, 2:20:43 PM7/10/08
to PHP General list
I need to send a header('Location:....') and send some data along with it -
how would I do this??

Thanks,

Alex

No virus found in this outgoing message. Scanned by AVG Free 8.0
Checked by AVG - http://www.avg.com
Version: 8.0.138 / Virus Database: 270.4.7/1544 - Release Date: 10/07/2008
07:37

Richard Heyes

unread,
Jul 10, 2008, 2:32:16 PM7/10/08
to Alex Chamberlain, PHP General list
Alex Chamberlain wrote:
> I need to send a header('Location:....') and send some data along with it -
> how would I do this??

Two methods:

1. Use the query string. Eg

header('Location: http://www.xxx.com?name=value&name2=value2');

2. Use sessions

--
Richard Heyes

Employ me:
http://www.phpguru.org/cv

Daniel Brown

unread,
Jul 10, 2008, 2:58:38 PM7/10/08
to rich...@phpguru.org, Alex Chamberlain, PHP General list
On Thu, Jul 10, 2008 at 2:32 PM, Richard Heyes <rich...@phpguru.org> wrote:
>
> 1. Use the query string. Eg
>
> header('Location: http://www.xxx.com?name=value&name2=value2');

That's GET, not POST, as the subject requests. ;-P

> 2. Use sessions

.... if you're not trying to POST the data and are staying within
the same domain on the same server. ;-P

--
</Daniel P. Brown>
Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

Daniel Brown

unread,
Jul 10, 2008, 2:37:42 PM7/10/08
to Alex Chamberlain, PHP General list
On Thu, Jul 10, 2008 at 2:20 PM, Alex Chamberlain
<p...@alexchamberlain.co.uk> wrote:
> I need to send a header('Location:....') and send some data along with it -
> how would I do this??

You probably want to use cURL:

http://php.net/curl

Eric Butera

unread,
Jul 10, 2008, 3:12:13 PM7/10/08
to Daniel Brown, rich...@phpguru.org, Alex Chamberlain, PHP General list
On Thu, Jul 10, 2008 at 2:58 PM, Daniel Brown <para...@gmail.com> wrote:
> On Thu, Jul 10, 2008 at 2:32 PM, Richard Heyes <rich...@phpguru.org> wrote:
>>
>> 1. Use the query string. Eg
>>
>> header('Location: http://www.xxx.com?name=value&name2=value2');
>
> That's GET, not POST, as the subject requests. ;-P
>
>> 2. Use sessions
>
> .... if you're not trying to POST the data and are staying within
> the same domain on the same server. ;-P

I'm pretty sure he means persist POST data on the forwarded request.

Shawn McKenzie

unread,
Jul 10, 2008, 3:37:11 PM7/10/08
to php-g...@lists.php.net
Daniel Brown wrote:
> On Thu, Jul 10, 2008 at 2:32 PM, Richard Heyes <rich...@phpguru.org> wrote:
>> 1. Use the query string. Eg
>>
>> header('Location: http://www.xxx.com?name=value&name2=value2');
>
> That's GET, not POST, as the subject requests. ;-P
>
>> 2. Use sessions
>
> .... if you're not trying to POST the data and are staying within
> the same domain on the same server. ;-P
>

With all that in mind, if you must POST then you can do something like this:

$data = addslashes("yourvar=$yourdata&secondvar=$moredata"); //just like get

header('POST /some/path/to/somefile.php HTTP/1.1');
header('Host: www.example.com');
header("Content-Type: application/x-www-form-urlencoded");
header("Content-Length: " . strlen($data));
header($data);

-Shawn

M. Sokolewicz

unread,
Jul 10, 2008, 7:55:13 PM7/10/08
to Shawn McKenzie, php-g...@lists.php.net

Have you tried it? I very much doubt that would work, considering
neither GET nor POST are valid in a RESPONSE (which is what you're
sending), they're only valid in REQUEST headers (which you're not in
right now, that's the browser's domain)

mrclay

unread,
Jul 11, 2008, 9:09:00 AM7/11/08
to
On Jul 10, 7:55 pm, tula...@php.net ("M. Sokolewicz") wrote:
> neither GET nor POST are valid in a RESPONSE (which is what you're
> sending), they're only valid in REQUEST headers (which you're not in
> right now, that's the browser's domain)

Right, the user's *browser* has to send the request. So return a
hidden form that submits with Javascript:

<form action='url' method='post'><div>
<?php foreach($data as $key => $val): ?>
<input type='hidden'
name='<?php echo htmlspecialchars($key, ENT_QUOTES); ?>'
value='<?php echo htmlspecialchars($val, ENT_QUOTES); ?>' />
<?php endforeach; ?>
<input type='submit' name='__ignoreMe' value='Click to continue...' />
</div></form>
<script type='text/javascript'>
window.onload = function () { document.forms[0].submit(); };
</script>

Steve

tedd

unread,
Jul 11, 2008, 12:12:02 PM7/11/08
to Alex Chamberlain, PHP General list
At 7:20 PM +0100 7/10/08, Alex Chamberlain wrote:
>I need to send a header('Location:....') and send some data along with it -
>how would I do this??
>
>Thanks,
>
>Alex

Alext:

Or you could just:

ob_clean();
include('theNextScript.php');
exit();

The variable in your parent script will be "passed" to the next script.

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

Alex Chamberlain

unread,
Jul 11, 2008, 12:26:35 PM7/11/08
to PHP General list
Ahh, but they are on different webservers....

At the moment, I am just using a query string. How long is the limit of the
query string??

Alex

> No virus found in this incoming message.


> Checked by AVG - http://www.avg.com

> Version: 8.0.138 / Virus Database: 270.4.7/1546 - Release Date:
> 11/07/2008 06:47

No virus found in this outgoing message. Scanned by AVG Free 8.0
Checked by AVG - http://www.avg.com

Version: 8.0.138 / Virus Database: 270.4.7/1546 - Release Date: 11/07/2008
06:47

No virus found in this outgoing message. Scanned by AVG Free 8.0
Checked by AVG - http://www.avg.com

Version: 8.0.138 / Virus Database: 270.4.7/1546 - Release Date: 11/07/2008
06:47

Daniel Brown

unread,
Jul 11, 2008, 12:37:06 PM7/11/08
to Alex Chamberlain, PHP General list
On Fri, Jul 11, 2008 at 12:26 PM, Alex Chamberlain
<p...@alexchamberlain.co.uk> wrote:
> Ahh, but they are on different webservers....

That's why I mentioned cURL at the very beginning, if it had to be
done as a POST request.

> At the moment, I am just using a query string. How long is the limit of the
> query string??

There is no official limit in the protocol, but you may want to
check out Section 3.2.1 of RFC 2068 for more on that.

The limits are in what the client is capable of sending, and what
the server is capable of receiving. A quick S of TFW should give you
the information you need regarding PHP and the remote server's
configuration.

tedd

unread,
Jul 11, 2008, 1:07:21 PM7/11/08
to PHP General list
At 12:37 PM -0400 7/11/08, Daniel Brown wrote:
>On Fri, Jul 11, 2008 at 12:26 PM, Alex Chamberlain
><p...@alexchamberlain.co.uk> wrote:
>> Ahh, but they are on different webservers....
>
> That's why I mentioned cURL at the very beginning, if it had to be
>done as a POST request.
>
>> At the moment, I am just using a query string. How long is the limit of the
>> query string??
>
> There is no official limit in the protocol, but you may want to
>check out Section 3.2.1 of RFC 2068 for more on that.
>
> The limits are in what the client is capable of sending, and what
>the server is capable of receiving. A quick S of TFW should give you
>the information you need regarding PHP and the remote server's
>configuration.

Incidentally, I did some minor testing on this a few years ago and
found the lengths vary greatly between servers.

Daniel Brown

unread,
Jul 11, 2008, 1:19:36 PM7/11/08
to tedd, PHP General list
On Fri, Jul 11, 2008 at 1:07 PM, tedd <tedd.s...@gmail.com> wrote:
>
> Incidentally, I did some minor testing on this a few years ago and found the
> lengths vary greatly between servers.

.... and browsers. If I remember correctly, on Winblows alone,
Opera is capable of somewhere in the 4,500 character range, while
Internet Exploder is only capable of 2048+slack (2083 bytes). And
pre-1.0 HTTP days, it was common for many servers not to accept more
than 255 characters on GET.

tedd

unread,
Jul 11, 2008, 3:18:15 PM7/11/08
to PHP General list
At 1:19 PM -0400 7/11/08, Daniel Brown wrote:
>On Fri, Jul 11, 2008 at 1:07 PM, tedd <tedd.s...@gmail.com> wrote:
>>
>> Incidentally, I did some minor testing on this a few years ago and found the
>> lengths vary greatly between servers.
>
> .... and browsers. If I remember correctly, on Winblows alone,
>Opera is capable of somewhere in the 4,500 character range, while
>Internet Exploder is only capable of 2048+slack (2083 bytes). And
>pre-1.0 HTTP days, it was common for many servers not to accept more
>than 255 characters on GET.


Yes, those are generally the numbers I found as well.

In my more current test, I had one test that exceeded 5000
characters, but most were in the 2000 character range.

So what it boils down to is, you can send a respectable number of
characters via a GET, but if it's going to be in the 1K range, it's
best to test (it's best to test anyway).

0 new messages