Connecting Tech Pros Worldwide Help | Site Map

Do I need to use isset?

  #1  
Old November 22nd, 2008, 12:55 AM
Bill H
Guest
 
Posts: n/a
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
  #2  
Old November 22nd, 2008, 01:05 AM
Jerry Stuckle
Guest
 
Posts: n/a

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
==================
  #3  
Old November 22nd, 2008, 02:45 AM
larry@portcommodore.com
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use a form to insert OR update fjm1967 answers 14 September 12th, 2007 07:32 AM
How to use subprocess Nicolas Fleury answers 4 July 19th, 2005 12:00 AM
Do I need to escape this code? Rod Carrol answers 14 July 17th, 2005 01:01 PM
Accessing $_SESSION variables in PHP5 needs isset() first? Pedro Fonseca answers 2 July 17th, 2005 08:31 AM