By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,707 Members | 1,442 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,707 IT Pros & Developers. It's quick & easy.

if(is_array($_POST)) always = TRUE - why?

P: n/a

Folks,

I test if my PHP should process form data by checking if $_POST is an
array - However I always find its condition proves true - Why or
alternatvily, what other method can one use to check for this sort of
situation?

<?
if(is_array($_POST))
{ die("<h1>here</h1>"); }
?>

I have tried isset() too and this also returns TRUE when it should be
false... must I always test with a count($_POST)==0?

ideas/solutions/anyone?

most appreciated - via the newsgroup
thanks
randelld
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Thu, 30 Oct 2003 23:00:29 GMT, "Randell D."
<yo**************************@yahoo.com> wrote:
I test if my PHP should process form data by checking if $_POST is an
array - However I always find its condition proves true - Why or
alternatvily, what other method can one use to check for this sort of
situation?
$_POST _is_ always an array.
<?
if(is_array($_POST))
{ die("<h1>here</h1>"); }
?>

I have tried isset() too and this also returns TRUE when it should be
false...
No, it should always be true. $_POST, $_GET, etc. are all superglobal arrays,
which are always defined.
must I always test with a count($_POST)==0?


Yes.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #2

P: n/a
Randell D. <yo**************************@yahoo.com> wrote:
I have tried isset() too and this also returns TRUE when it should be
false... must I always test with a count($_POST)==0?


Check for a value that should be in the post (like the submit button or
other mandatory keys):

if(array_key_exists('foo',$_POST))
{
...
}

--

Daniel Tryba

Jul 17 '05 #3

P: n/a
"Randell D." <yo**************************@yahoo.com> wrote in message news:<hKgob.227810$pl3.442@pd7tw3no>...
Folks,

I test if my PHP should process form data by checking if $_POST is an
array - However I always find its condition proves true - Why or
alternatvily, what other method can one use to check for this sort of
situation?

<?
if(is_array($_POST))
{ die("<h1>here</h1>"); }
?>

I have tried isset() too and this also returns TRUE when it should be
false... must I always test with a count($_POST)==0?

ideas/solutions/anyone?
1. if ($_POST) //if form posted??

2. if (isset($_POST['foo'])) //if form posted by clicking "foo"
button. Can be used if more than one submit button is present or more
than one form is present.
most appreciated - via the newsgroup


Is there anyone to reply via email :-/

---
"If there is a God, he must be a sadist!"
Email: rrjanbiah-at-Y!com
Jul 17 '05 #4

P: n/a
Carved in mystic runes upon the very living rock, the last words of Randell
D. of comp.lang.php make plain:
I test if my PHP should process form data by checking if $_POST is an
array - However I always find its condition proves true - Why or
alternatvily, what other method can one use to check for this sort of
situation?


if ($_SERVER['REQUEST_METHOD'] == "POST")

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.