Jump to content

PHP Security, protecting from sql injections etc.


Recommended Posts

Hi, I have been reading the quide at http://www.dagondesign.com/articles/writing-secure-php-scripts-part-1/ and was just wondering if I would be safe to use these functions in my code.

 

For displaying content from db:

function fix_for_page($value){
    $value = htmlspecialchars(trim($value));
    if (get_magic_quotes_gpc()) 
        $value = stripslashes($value);
    return $value;
}

 

for posting stuff to db:

function fix_for_mysql($value){
    if (get_magic_quotes_gpc())
        $value = stripslashes($value);
    $value = mysql_real_escape_string($value);
    return $value;
}

 

I guess I would just call the function up on every variable that either gets posted to my db, or viewed from my db?

 

Does anyone have any other recommendations?

 

I am also in the process of recoding a lot of my pages as I was unaware of register globals problems, so if anyone has tips there also?

 

 

thank you all, Shaun

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.