Jump to content

Security in PHP [Two functions I made]


SyLon

Recommended Posts

Hello everyone!

After reading some php security articles, I've created 2 function to prevent sql injection and display html tags correctly.

The first one is for user input formatting:

 

function _INPUT($name)
{
    if ($_SERVER['REQUEST_METHOD'] == 'GET')
        return mysql_real_escape_string(strip_tags($_GET[$name]));
    if ($_SERVER['REQUEST_METHOD'] == 'POST')
        return mysql_real_escape_string(strip_tags($_POST[$name]));
}

 

The second one is for output:

 

function _STR($string) {

return nl2br(htmlspecialchars(stripcslashes($string)));

}

 

What do you think about those two function? Will they provide the maximum security for my websites?

Thanks, Leon.

 

Link to comment
https://forums.phpfreaks.com/topic/80459-security-in-php-two-functions-i-made/
Share on other sites

So it would look like this?

function _INPUT($name)
{
    if ($_SERVER['REQUEST_METHOD'] == 'GET')
        //return mysql_real_escape_string(strip_tags($_GET[$name]));
        return mysql_real_escape_string(htmlentities($_GET[$name], ENT_QUOTES));
    if ($_SERVER['REQUEST_METHOD'] == 'POST')
        //return mysql_real_escape_string(strip_tags($_POST[$name]));
        return mysql_real_escape_string(htmlentities($_POST[$name], ENT_QUOTES));
}

Also, what do you think about the _STR function?

Thanks, Leon.

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.