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

Link to comment
Share on other sites

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.