Maybe. Probably.
,

PHP Variable Handling: isset() and empty()

i’ve probably learned more important and practical information about PHP development from phpbuilder dot com than anywhere else. that’s not to say that other resources aren’t as good, i’m just saying that, when it came down to trying my first few bits of conditional logic, or my first run-in with header()PHPBuilder.com happens to be where i’ve learned much of what i know… the stuff that’s kept me above water!Not to be disproved, here’s yet another great bit i learned just recently. I was already aware, and had used in many situations the Variable Handling Functions, isset() and empty(), but this user from the forum explains it in such a way that it helped me to really develop a practical understanding of the two functions.

Im not 100% sure Im with you. Are you trying to protect pages that should only be accessed when requested by a form for instance?
PHP Code:
if (isset($_POST['input'])) {
// process.
} else {
// reject request.
}

In this example, $_POST[‘input’] simply will not exist (will not be set) unless the page is requested by a form.However, in allot of cases, you would want more than the form to simply have been submiitted. You’ll want it to have a value. In this situation, empty() is often a better choice.
PHP Code:
if (!empty($_POST['input'])) {
// form was submitted and contains a value.
} else {
// form not submitted OR contains no value.
}
Note that empty() will return true if the value it is testing is false.empty() and isset() work exactly the same with sessions.

PHPBuilder.com
http://phpbuilder.com/board/showpost.php?p=10722710

Whatchu do


Leave a Reply

Your email address will not be published. Required fields are marked *