Connecting Tech Pros Worldwide Forums | Help | Site Map

Knowing the form action

Fabio
Guest
 
Posts: n/a
#1: Aug 21 '07
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



petersprc
Guest
 
Posts: n/a
#2: Aug 21 '07

re: Knowing the form action


If you had a button like

<input type=button name=btn value=" OK ">

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" <znt.fa...@virgilio.itwrote:
Quote:
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

Fabio
Guest
 
Posts: n/a
#3: Aug 21 '07

re: Knowing the form action


"petersprc" <petersprc@gmail.comha scritto nel messaggio
news:1187682646.281398.67090@q3g2000prf.googlegrou ps.com...
Quote:
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 :(



rf
Guest
 
Posts: n/a
#4: Aug 21 '07

re: Knowing the form action



"Fabio" <znt.fabio@virgilio.itwrote in message
news:46ca9d2d$0$17947$4fafbaef@reader1.news.tin.it ...
Quote:
"petersprc" <petersprc@gmail.comha scritto nel messaggio
news:1187682646.281398.67090@q3g2000prf.googlegrou ps.com...
>
Quote:
>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.


fabian.sorqvist@gmail.com
Guest
 
Posts: n/a
#5: Aug 21 '07

re: Knowing the form action


$_SERVER['REQUEST_METHOD']

Contains which method you used to access the page



fabian.sorqvist@gmail.com
Guest
 
Posts: n/a
#6: Aug 21 '07

re: Knowing the form action


On 21 Aug, 10:07, "Fabio" <znt.fa...@virgilio.itwrote:
Quote:
"petersprc" <peters...@gmail.comha scritto nel messaggionews:1187682646.281398.67090@q3g2000prf.g ooglegroups.com...
>
Quote:
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 ^^

NC
Guest
 
Posts: n/a
#7: Aug 21 '07

re: Knowing the form action


On Aug 21, 12:16 am, "Fabio" <znt.fa...@virgilio.itwrote:
Quote:
>
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.
Quote:
- 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

Closed Thread