Jump to content

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

Edited by devilsvein
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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.