Jump to content

Function returns blank values


devilsvein

Recommended Posts

Trying to create a function to sanitize some variables. What I have done so far is:

 


function securevar ($var)
{
$var = htmlentities($var, ENT_QUOTES);
if ( strlen ($var) >= 9)
{
$var == "401";
}
}

 

database results perfectly come and work if I dont use the above function but as soon as I do:

 



$username = securevar($row['Username']);

 

It returns blank and no error message. Aslo forgot to say var_dump on $username returns NULL

Link to comment
https://forums.phpfreaks.com/topic/273328-function-returns-blank-values/
Share on other sites


function securevar($var)
{
$var = htmlentities($var, ENT_QUOTES);
if ( strlen ($var) >= 9)
{
$var == "401";
}
return $var;
}


$username = securevar($row['Username']);

 

Basically what Im expecting to happen is that $row['username']; goes into the function and gets sanitized to prevent xss attacks.

 

it then returns to the same variable the result which is now sanitized. If after being sanitized it has more then 9 digits I print 401 instead of the sanitized name.

 

This then gets stored in a new variable for ease of remebering which is $username

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.