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

get or post?

1 view
Skip to first unread message

Larry

unread,
Jan 25, 2010, 5:09:12 AM1/25/10
to
Is there a way to know if the current page is a result of a get or
post?

Thomas 'PointedEars' Lahn

unread,
Jan 25, 2010, 6:13:11 AM1/25/10
to
Larry wrote:

> Is there a way to know if the current page is a result of a get or
> post?

Yes.


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)

The Natural Philosopher

unread,
Jan 25, 2010, 6:35:28 AM1/25/10
to
Thomas 'PointedEars' Lahn wrote:
> Larry wrote:
>
>> Is there a way to know if the current page is a result of a get or
>> post?
>
> Yes.
>
and of course, no.

Depending on where you are looking at the 'current page' :-)

>
> PointedEars

Scott Sauyet

unread,
Jan 25, 2010, 6:36:33 AM1/25/10
to
On Jan 25, 6:13 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>

wrote:
>> Is there a way to know if the current page is a result of a get or
>> post?
>
> Yes.

No.

At least, assuming you're discussing doing this from Javascript in a
web browser. For any POST you perform, the server could send a
redirect to a GET.

If you have control on the server-side, you could echo the request
type into a JS variable; in PHP it might be

var httpMethod = "<?php echo $_SERVER['REQUEST_METHOD']; ?>"

Good luck,

-- Scott

Thomas 'PointedEars' Lahn

unread,
Jan 25, 2010, 7:24:59 AM1/25/10
to
Scott Sauyet wrote:

> Thomas 'PointedEars' Lahn wrote:
>>> Is there a way to know if the current page is a result of a get or
>>> post?
>> Yes.

^^^^


> No.
>
> At least, assuming you're discussing doing this from Javascript in a
> web browser. For any POST you perform, the server could send a
> redirect to a GET.
>
> If you have control on the server-side, you could echo the request
> type into a JS variable; in PHP it might be
>
> var httpMethod = "<?php echo $_SERVER['REQUEST_METHOD']; ?>"

See, there is a way :)

The Natural Philosopher

unread,
Jan 25, 2010, 11:49:16 AM1/25/10
to
Thomas 'PointedEars' Lahn wrote:
> Scott Sauyet wrote:
>
>> Thomas 'PointedEars' Lahn wrote:
>>>> Is there a way to know if the current page is a result of a get or
>>>> post?
>>> Yes.
> ^^^^
>> No.
>>
>> At least, assuming you're discussing doing this from Javascript in a
>> web browser. For any POST you perform, the server could send a
>> redirect to a GET.
>>
>> If you have control on the server-side, you could echo the request
>> type into a JS variable; in PHP it might be
>>
>> var httpMethod = "<?php echo $_SERVER['REQUEST_METHOD']; ?>"
>
> See, there is a way :)
>
>
Right little humourist, is our resident elf...;-)

> PointedEars

Evertjan.

unread,
Jan 25, 2010, 4:00:00 PM1/25/10
to
Thomas 'PointedEars' Lahn wrote on 25 jan 2010 in comp.lang.javascript:
> Scott Sauyet wrote:
>
>> Thomas 'PointedEars' Lahn wrote:
>>>> Is there a way to know if the current page is a result of a get or
>>>> post?
>>> Yes.
> ^^^^
>> No.
>>
>> At least, assuming you're discussing doing this from Javascript in a
>> web browser. For any POST you perform, the server could send a
>> redirect to a GET.
>>
>> If you have control on the server-side, you could echo the request
>> type into a JS variable; in PHP it might be
>>
>> var httpMethod = "<?php echo $_SERVER['REQUEST_METHOD']; ?>"
>
> See, there is a way :)

No there is not.

The new page can never know if the page request is
1 a result of a bona fide form-get
or
2 just from a link contaning an URL with querystring.

You can never know if the page request is from a
form-post just if it tests positive a querystring
as this could be contained in the form post action='...?a=b'.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Scott Sauyet

unread,
Jan 25, 2010, 4:25:20 PM1/25/10
to
On Jan 25, 4:00 pm, "Evertjan." <exjxw.hannivo...@interxnl.net> wrote:
> The new page can never know if the page request is
> 1 a result of a bona fide form-get
> or
> 2 just from a link contaning an URL with querystring.

I'm not sure that is a meaningful distinction. At the HTTP level,
both are GET requests, so even the server doesn't distinguish this.

-- Scott

Evertjan.

unread,
Jan 25, 2010, 5:27:57 PM1/25/10
to

No, they could also be POST requests at ther same time.

If you define a GET request als if without a querystring,
the whole OQ is meaningless.

The only interesting Q is if there is POST content
and if there is querytring content.

Eric Bednarz

unread,
Jan 25, 2010, 7:28:38 PM1/25/10
to
"Evertjan." <exjxw.ha...@interxnl.net> writes:

> Thomas 'PointedEars' Lahn wrote on 25 jan 2010 in comp.lang.javascript:

>> Scott Sauyet wrote:

>>> [OP, ed.]

>>>>> Is there a way to know if the current page is a result of a get or
>>>>> post?

>>> var httpMethod = "<?php echo $_SERVER['REQUEST_METHOD']; ?>"


>>
>> See, there is a way :)
>
> No there is not.

I read that as wanting to know the request method, and I would think
that a HTTP server cannot resolve a resource and send response headers
without knowing that.

I wonder what you read.

Eric Bednarz

unread,
Jan 25, 2010, 7:36:16 PM1/25/10
to
"Evertjan." <exjxw.ha...@interxnl.net> writes:

> Scott Sauyet wrote on 25 jan 2010 in comp.lang.javascript:
>
>> "Evertjan." <exjxw.hannivo...@interxnl.net> wrote:

>>> The new page can never know if the page request is
>>> 1 a result of a bona fide form-get
>>> or
>>> 2 just from a link contaning an URL with querystring.
>>
>> I'm not sure that is a meaningful distinction. At the HTTP level,
>> both are GET requests, so even the server doesn't distinguish this.
>
> No, they could also be POST requests at ther same time.

I would like an example of an HTTP request that simultaneously uses the
HTTP GET and POST methods.

Erwin Moller

unread,
Jan 26, 2010, 5:55:44 AM1/26/10
to
Eric Bednarz schreef:

Here is one:

<form action="whatever.php?id=12" Method="POST" name="testform">
Firstname: <input type="text" name="firstname">
<input type="submit">
</form>

Then from PHP (whatever.php):
-------------------------------
<pre>
GET contains:
<?php
print_r($_GET);
?>
POST contains:
<?php
print_r($_POST);
?>
</pre>
-------------------------------

It is a bit weird I admit, but it works just fine.


Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare

Scott Sauyet

unread,
Jan 26, 2010, 10:22:11 AM1/26/10
to
On Jan 26, 5:55 am, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spamyourself.com> wrote:
> Eric Bednarz schreef:

>> I would like an example of an HTTP request that simultaneously uses the
>> HTTP GET and POST methods.
>
> Here is one:
>
> <form action="whatever.php?id=12" Method="POST" name="testform">
> Firstname: <input type="text" name="firstname">
> <input type="submit">
> </form>
> [ ... ]

> It is a bit weird I admit, but it works just fine.

Well, this still is an HTTP POST request. PHP interprets the query
string of the URL as GET variables, but it is not a GET request.

-- Scott

Evertjan.

unread,
Jan 26, 2010, 2:10:35 PM1/26/10
to
Eric Bednarz wrote on 26 jan 2010 in comp.lang.javascript:

>>> See, there is a way :)
>>
>> No there is not.

Here you skip the explanation of the above "no ..."

> I read that

my sentence?

> as wanting to know the request method, and I would think
> that a HTTP server cannot resolve a resource and send response headers
> without knowing that.

What HTTP-server [is there such an animal?]?

What Resource?

Why should a server without serverside programming ability [if that is what
you mean by HTTP-server], do anything with the POST content of the request
header?

> and send response headers without knowing that.

The request querystring has no special request or response headers.

The POST content is in the request header, not in the response header.

I think!!!



> I wonder what you read.

Where? In the Header?

Evertjan.

unread,
Jan 26, 2010, 2:16:59 PM1/26/10
to

So we should define a GET request in the OQ sense just as a any request
that is not a HTTP POST request [disregarding the HEAD request which has no
clientside coding ability]?

You could do that, but what would be the use for the OP?

Scott Sauyet

unread,
Jan 26, 2010, 3:08:19 PM1/26/10
to
On Jan 26, 2:16 pm, "Evertjan." <exjxw.hannivo...@interxnl.net> wrote:
> Scott Sauyet wrote on 26 jan 2010 in comp.lang.javascript:
>> On Jan 26, 5:55ÿam, Erwin Moller

>> Well, this still is an HTTP POST request.  PHP interprets the query
>> string of the URL as GET variables, but it is not a GET request.
>
> So we should define a GET request in the OQ sense just as a any request
> that is not a HTTP POST request [disregarding the HEAD request which has no
> clientside coding ability]?

No, but there is a specific verb given in the HTTP specification that
is used for each request. If that request responds with a page, there
is no client-side way from that page to know what verb was used; of
course additional server-side help can easily be supplied. That's
what I said in my original response.

> You could do that, but what would be the use for the OP?

I don't know what the OP needs, but if it's to know, for instance,
that the current page is in response to a POST request, I believe that
this is not possible in general without server-side help.

-- Scott

Eric Bednarz

unread,
Jan 26, 2010, 6:28:17 PM1/26/10
to
"Evertjan." <exjxw.ha...@interxnl.net> writes:

> Eric Bednarz wrote on 26 jan 2010 in comp.lang.javascript:

>> I read that
>
> my sentence?

The OP’s question:

| Is there a way to know if the current page is a result of a get or
| post?

>> as wanting to know the request method, and I would think


>> that a HTTP server cannot resolve a resource and send response headers
>> without knowing that.
>
> What HTTP-server

I don’t know which HTTP server the OP uses. :-)

> What Resource?

The resource that tentatively wants to know if it is a result of a GET
or POST request.

> Why should a server without serverside programming ability [if that is what
> you mean by HTTP-server],

By HTTP server I mean a server that services HTTP requests.

> do anything with the POST content of the request
> header?

¿Que?

>> and send response headers without knowing that.
>
> The request querystring has no special request or response headers.

I think that this might be a pretty silly discussion.

> The POST content is in the request header,

I thought that POST data is send in the message body of the request.

> not in the response header.

I should better just have written ‘a response’.

The request method is stated in the request header, and is hopefully
accessible by server-side script (e.g. by the already mentioned
REQUEST_METHOD environment variable). Both response header and message
body may or may not depend on it.

The Natural Philosopher

unread,
Jan 26, 2010, 8:21:07 PM1/26/10
to
Evertjan. wrote:
> Thomas 'PointedEars' Lahn wrote on 25 jan 2010 in comp.lang.javascript:
>> Scott Sauyet wrote:
>>
>>> Thomas 'PointedEars' Lahn wrote:
>>>>> Is there a way to know if the current page is a result of a get or
>>>>> post?
>>>> Yes.
>> ^^^^
>>> No.
>>>
>>> At least, assuming you're discussing doing this from Javascript in a
>>> web browser. For any POST you perform, the server could send a
>>> redirect to a GET.
>>>
>>> If you have control on the server-side, you could echo the request
>>> type into a JS variable; in PHP it might be
>>>
>>> var httpMethod = "<?php echo $_SERVER['REQUEST_METHOD']; ?>"
>> See, there is a way :)
>
> No there is not.
>
> The new page can never know

anythinmg. new pages are not intelligent, nor even computing engyns

Straw man. The ELF shot you.

The Natural Philosopher

unread,
Jan 26, 2010, 8:21:33 PM1/26/10
to

It does

> -- Scott

The Natural Philosopher

unread,
Jan 26, 2010, 8:22:24 PM1/26/10
to

I do it somewhat regularly..

VERY possible with javascript.

The Natural Philosopher

unread,
Jan 26, 2010, 8:23:18 PM1/26/10
to
IUf that isn't what a GET is, I dunno WTF is...
> -- Scott

The Natural Philosopher

unread,
Jan 26, 2010, 8:23:53 PM1/26/10
to
True. Which was the Elf's point.

> -- Scott

The Natural Philosopher

unread,
Jan 26, 2010, 8:25:18 PM1/26/10
to

The Elf read it exactly as it was written.

Is there a way to know? yes. No specification was given as to the entity
that was to do the determination.

Eric Bednarz

unread,
Jan 26, 2010, 8:54:43 PM1/26/10
to

While that may not be the kind of example I was hoping for, it was the
one I was expecting, so thank you.

> VERY possible with javascript.

I won’t doubt that, but writing an HTTP user agent and an HTTP server
that extend HTTP 1.1 in javascript is too ambitious a project for
me.

Sherm Pendley

unread,
Jan 26, 2010, 11:27:59 PM1/26/10
to
The Natural Philosopher <t...@invalid.invalid> writes:

> Scott Sauyet wrote:
>>
>> Well, this still is an HTTP POST request. PHP interprets the query
>> string of the URL as GET variables, but it is not a GET request.
>

> [If] that isn't what a GET is, I dunno WTF is...

The request method is given as part of the HTTP headers in the request
that the browser sends. If a request begins with "GET foo.html HTTP/1.0",
it's a GET request. If it begins with "POST foo.php?bar=baz HTTP/1.0",
it's a POST request. A GET request can be HTTP headers alone, while a
POST has to have a message body too.

It's the verb in the first part of the request that determines the method,
not the presence or lack of a query string in the requested URL.

More info:
<http://www.jmarshall.com/easy/http/>

A *lot* more info:
<http://www.w3.org/Protocols/rfc2616/rfc2616.html>

sherm--

The Natural Philosopher

unread,
Jan 27, 2010, 9:48:03 AM1/27/10
to
Sherm Pendley wrote:
> The Natural Philosopher <t...@invalid.invalid> writes:
>
>> Scott Sauyet wrote:
>>> Well, this still is an HTTP POST request. PHP interprets the query
>>> string of the URL as GET variables, but it is not a GET request.
>> [If] that isn't what a GET is, I dunno WTF is...
>
> The request method is given as part of the HTTP headers in the request
> that the browser sends. If a request begins with "GET foo.html HTTP/1.0",
> it's a GET request. If it begins with "POST foo.php?bar=baz HTTP/1.0",
> it's a POST request. A GET request can be HTTP headers alone, while a
> POST has to have a message body too.
>
> It's the verb in the first part of the request that determines the method,
> not the presence or lack of a query string in the requested URL.
>

what about GET foo.php?bar=baz HTTP/1.0"

That works:

You can use a URL to point to a program that will correctly receive that
command line and set up a response depending on it

POST foo.php?bar=baz HTTP/1.0 will be using post get and post variables,
if any are included in the message body.


its certainly possible to set a form variable and invoke a URL with a
get variable on the back and pick up BOTH variables.

Sherm Pendley

unread,
Jan 27, 2010, 3:01:45 PM1/27/10
to
The Natural Philosopher <t...@invalid.invalid> writes:

> Sherm Pendley wrote:
>>
>> The request method is given as part of the HTTP headers in the request
>> that the browser sends. If a request begins with "GET foo.html HTTP/1.0",
>> it's a GET request. If it begins with "POST foo.php?bar=baz HTTP/1.0",
>> it's a POST request. A GET request can be HTTP headers alone, while a
>> POST has to have a message body too.
>>
>> It's the verb in the first part of the request that determines the method,
>> not the presence or lack of a query string in the requested URL.
>
> what about GET foo.php?bar=baz HTTP/1.0"

What about it? The verb is GET, so it's a GET request, whether or not
the URL has a query string.

> POST foo.php?bar=baz HTTP/1.0 will be using post get and post
> variables, if any are included in the message body.

The verb before the URL is POST, so it's a POST request, whether or
not the URL has a query string.

The fact that PHP stuffs query string variables into a PHP variable
called $_GET is misleading, since it does so regardless of what kind
of HTTP request method was actually sent by the browser.

> its certainly possible to set a form variable and invoke a URL with a
> get variable on the back and pick up BOTH variables.

It's possible to send a POST request that includes variables as part
of the message body, and other variables in the query string. Doing so,
however, does not turn it into something other than a POST request.

sherm--

The Natural Philosopher

unread,
Jan 27, 2010, 5:12:07 PM1/27/10
to
Sherm Pendley wrote:
> The Natural Philosopher <t...@invalid.invalid> writes:
>
>> Sherm Pendley wrote:
>>> The request method is given as part of the HTTP headers in the request
>>> that the browser sends. If a request begins with "GET foo.html HTTP/1.0",
>>> it's a GET request. If it begins with "POST foo.php?bar=baz HTTP/1.0",
>>> it's a POST request. A GET request can be HTTP headers alone, while a
>>> POST has to have a message body too.
>>>
>>> It's the verb in the first part of the request that determines the method,
>>> not the presence or lack of a query string in the requested URL.
>> what about GET foo.php?bar=baz HTTP/1.0"
>
> What about it? The verb is GET, so it's a GET request, whether or not
> the URL has a query string.
>
>> POST foo.php?bar=baz HTTP/1.0 will be using post get and post
>> variables, if any are included in the message body.
>
> The verb before the URL is POST, so it's a POST request, whether or
> not the URL has a query string.
>
> The fact that PHP stuffs query string variables into a PHP variable
> called $_GET is misleading, since it does so regardless of what kind
> of HTTP request method was actually sent by the browser.

WEll no, that's where you are wrong. It stuffs Get into $_GET and post
into $_POST.

The CGI standard defines GET method as using the URL and POST method as
using the message body.

NOTHING to do with whether the browser issues a GET or a POST *command*,
except I am not sure what a server would do with a GET command with a
body attached..

If ypu send as POST COMMAND, the server accepts both url encoded and
body encoded data. AND SEPARATES THEM.


.

>
>> its certainly possible to set a form variable and invoke a URL with a
>> get variable on the back and pick up BOTH variables.
>
> It's possible to send a POST request that includes variables as part
> of the message body, and other variables in the query string. Doing so,
> however, does not turn it into something other than a POST request.
>

But it does turn it into somethimg that uses the GET method of CGI
interfacing.

Don't confuse the two.

> sherm--

Sherm Pendley

unread,
Feb 1, 2010, 11:25:15 AM2/1/10
to
The Natural Philosopher <t...@invalid.invalid> writes:

> Sherm Pendley wrote:


>> The Natural Philosopher <t...@invalid.invalid> writes:
>>
>> The fact that PHP stuffs query string variables into a PHP variable
>> called $_GET is misleading, since it does so regardless of what kind
>> of HTTP request method was actually sent by the browser.
>
> WEll no, that's where you are wrong. It stuffs Get into $_GET and post
> into $_POST.

I hate to be the one to break it to you, but not everyone who disagrees
with you is wrong.

> The CGI standard defines GET method as using the URL and POST method
> as using the message body.

LOL! GET and POST are defined by HTTP.

You're too clueless to argue with - you'll have to educate yourself
without my help from here on out. Sorry.

> But it does turn it into somethimg that uses the GET method of CGI
> interfacing.
>
> Don't confuse the two.

I'm not confused jackass. And f**k you for saying so.

*plonk*

sherm--

The Natural Philosopher

unread,
Feb 1, 2010, 2:32:28 PM2/1/10
to

GET and POST are also defined in the English dictionary.

You might care to GET a life and POST your angst somewhere else.


> *plonk*
>
> sherm--

0 new messages