Jump to content

Isset always true ?


Rommeo

Recommended Posts

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. )

Link to comment
https://forums.phpfreaks.com/topic/127077-isset-always-true/
Share on other sites

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
}

Link to comment
https://forums.phpfreaks.com/topic/127077-isset-always-true/#findComment-657446
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.