Knowing the form action

Knowing the form action

am 21.08.2007 09:16:36 von Zanna

Hi!

Is there a way to know if the page is:
- directly called from the browser
- called by the submit button pressed in POST mode
- called by the submit button pressed in GET mode

?

Thanks

Re: Knowing the form action

am 21.08.2007 09:50:46 von petersprc

If you had a button like



You could check:

if (isset($_POST['btn'])) {
echo 'Button post.';
} elseif (isset($_GET['btn'])) {
echo 'Button get.';
} else {
echo 'Page view.';
}

On Aug 21, 3:16 am, "Fabio" wrote:
> Hi!
>
> Is there a way to know if the page is:
> - directly called from the browser
> - called by the submit button pressed in POST mode
> - called by the submit button pressed in GET mode
>
> ?
>
> Thanks

Re: Knowing the form action

am 21.08.2007 10:07:10 von Zanna

"petersprc" ha scritto nel messaggio
news:1187682646.281398.67090@q3g2000prf.googlegroups.com...

> if (isset($_POST['btn'])) {
> echo 'Button post.';
> } elseif (isset($_GET['btn'])) {
> echo 'Button get.';
> } else {
> echo 'Page view.';
> }

mmm... I'm doing something like

if (count($_POST)> 0) {
echo 'Button post.';
} elseif (count($_GET)> 0) {
echo 'Button get.';
} else {
echo 'Page view.';
}

but if I visit

http://www.mysite.com/?submitted=false

I get "Button get." also if I didn't pressed nothing :(

Re: Knowing the form action

am 21.08.2007 10:16:42 von rf

"Fabio" wrote in message
news:46ca9d2d$0$17947$4fafbaef@reader1.news.tin.it...
> "petersprc" ha scritto nel messaggio
> news:1187682646.281398.67090@q3g2000prf.googlegroups.com...
>
>> if (isset($_POST['btn'])) {
>> echo 'Button post.';
>> } elseif (isset($_GET['btn'])) {
>> echo 'Button get.';
>> } else {
>> echo 'Page view.';
>> }
>
> mmm... I'm doing something like
>
> if (count($_POST)> 0) {
> echo 'Button post.';
> } elseif (count($_GET)> 0) {
> echo 'Button get.';
> } else {
> echo 'Page view.';
> }
>
> but if I visit
>
> http://www.mysite.com/?submitted=false
>
> I get "Button get." also if I didn't pressed nothing :(

Because that is how get data is sent to the server. Sever side you simply
can not tell. Why do you need to?

--
Richard.

Re: Knowing the form action

am 21.08.2007 10:18:58 von fabian.sorqvist

$_SERVER['REQUEST_METHOD']

Contains which method you used to access the page

Re: Knowing the form action

am 21.08.2007 10:23:37 von fabian.sorqvist

On 21 Aug, 10:07, "Fabio" wrote:
> "petersprc" ha scritto nel messaggionews:1187682646.281398.67090@q3g2000prf.googlegroup s.com...
>
> > if (isset($_POST['btn'])) {
> > echo 'Button post.';
> > } elseif (isset($_GET['btn'])) {
> > echo 'Button get.';
> > } else {
> > echo 'Page view.';
> > }
>
> mmm... I'm doing something like
>
> if (count($_POST)> 0) {
> echo 'Button post.';} elseif (count($_GET)> 0) {
>
> echo 'Button get.';} else {
>
> echo 'Page view.';
>
> }
>
> but if I visit
>
> http://www.mysite.com/?submitted=false
>
> I get "Button get." also if I didn't pressed nothing :(

elseif (count($_GET)> 0) {
echo 'Button get.';}

if you access the url http://www.mysite.com/?submitted=false, then you
have something in your $_GET variable, that's why it displays button
get ^^

Re: Knowing the form action

am 21.08.2007 20:24:36 von nc

On Aug 21, 12:16 am, "Fabio" wrote:
>
> Is there a way to know if the page is:
> - directly called from the browser

Directly meaning by typing the URL into the browser's address bar?
Yes, but it's not 100% reliable; $_SERVER['HTTP_REFERER'] should be
empty.

> - called by the submit button pressed in POST mode
> - called by the submit button pressed in GET mode

You can use $_SERVER['REQUEST_METHOD'], but you would do well to
remember that almost anything a browser does to access content can be
emulated by other programs.

Cheers,
NC