Connecting Tech Pros Worldwide Help | Site Map

Do I need to use isset?

Bill H
Guest
 
Posts: n/a
#1: Nov 22 '08
I have gotten into the habit of using isset for every $_POST variable,
checking that it is set before I even check to see if it contains
anything. For example:

if (isset($_POST['password']) && $_POST['password'] != "")

Is this something I need to do?

Would I get "undefined" errors if I just did this instead?

if ($_POST['password'] != "")

Bill H
Jerry Stuckle
Guest
 
Posts: n/a
#2: Nov 22 '08

re: Do I need to use isset?


Bill H wrote:
Quote:
I have gotten into the habit of using isset for every $_POST variable,
checking that it is set before I even check to see if it contains
anything. For example:
>
if (isset($_POST['password']) && $_POST['password'] != "")
>
Is this something I need to do?
>
Would I get "undefined" errors if I just did this instead?
>
if ($_POST['password'] != "")
>
Bill H
You will get notices if you have them enabled. Even if you don't, there
will be unnecessary processing to detect the notice and determine if
logging or display is appropriate.

You should ALWAYS check incoming $_GET or $_POST data to see if it is
indeed set.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
larry@portcommodore.com
Guest
 
Posts: n/a
#3: Nov 22 '08

re: Do I need to use isset?


I've made such things a common function (simple example):

function readPost($name) {
$val = ( isset( $_POST[$name] ) ? $_POST[$name] : '' );
// if possible, do some input filtering here
return $val;
}

$password = readPost('password');

As I learn new ways to filter you will just need to work on the
function - not all the input lines.
Do the same with $_GET and $_COOKIE.
Closed Thread