Page 1 of 1
Variables
Posted: Wed Aug 07, 2002 5:51 pm
by icesolid
I always use this code for checking for variables:
Code: Select all
if($var) {
} else {
}
But the other day someone told me that using this code:
Code: Select all
if($_GETї"var"]) {
} else {
}
Or this code:
Code: Select all
if(isset($_GETї"var"]) {
} else {
}
Would make my script better. Is that true?
Re: Variables
Posted: Wed Aug 07, 2002 11:21 pm
by protokol
Well, the best and most effective way to check for variables would be this:
if (strlen(trim($_GET['var'])) > 0) {
} else {
}
Posted: Thu Aug 08, 2002 2:20 am
by twigletmac
This article will explain Protokol's code:
http://www.phpcomplete.com/content.php?id=69
I knew I'd seen that somewhere recently

.
You use $_GET when you're checking for stuff coming from the URL's query string, you wouldn't use it for checking variables you had set within the script. For info on $_GET and the other predefined variables:
http://www.php.net/manual/en/language.v ... efined.php
I prefer using either
isset() or
empty() (depending on what I'm looking for) to check that variables exist before I try and use them but I also
trim() any user input.
Mac
Posted: Thu Aug 08, 2002 7:42 am
by protokol
Posted: Fri Aug 09, 2002 1:45 am
by twigletmac
Danger of cut and paste... (corrected it above too)
Mac