Rommeo Posted October 5, 2008 Share Posted October 5, 2008 Hi i have a login form and a logincheck.php file. when i enter directly to logincheck.php the function "isset" gives me true which is wrong. I think the way i m using for isset is true $username = $_POST['form_username']; $username = str_replace("_", "", $username); $username = trim($username); $usernameset = isset($username); echo "username = $username Username exist = $usernameset"; and the output is 1 Is there anything that i need to use additionaly with isset ? Is there any other option ? I will be glad if anyone can help. Thanx in advance. ( as far as i know isset gives true (1) when it's set otherwise zero. ) Quote Link to comment https://forums.phpfreaks.com/topic/127077-isset-always-true/ Share on other sites More sharing options...
Psycho Posted October 5, 2008 Share Posted October 5, 2008 isset() merely tells you if the variable has been defined, not whether it has a value or not. So, you could set the value to an empty string or a null value and isset() will return true. Try using !empty() Quote Link to comment https://forums.phpfreaks.com/topic/127077-isset-always-true/#findComment-657341 Share on other sites More sharing options...
genericnumber1 Posted October 5, 2008 Share Posted October 5, 2008 should also note that empty() will return true if the value is 0 (or bool false, but that can't happen from a form), so make sure a valid value is not 0. Quote Link to comment https://forums.phpfreaks.com/topic/127077-isset-always-true/#findComment-657344 Share on other sites More sharing options...
wildteen88 Posted October 5, 2008 Share Posted October 5, 2008 When using isset never do: $var = $_POST['var']; if(isset($var)) { // do something } As that will always evaluate to true. You should do this instead: if(isset($_POST['var']) && !empty($_POST['var'])) { $var = $_POST['var']; // do something } Quote Link to comment https://forums.phpfreaks.com/topic/127077-isset-always-true/#findComment-657446 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.