Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: SQL Injections

  1. #1
    Join Date
    Jun 2006
    Posts
    4,832
    Tokens
    0

    Latest Awards:

    Default SQL Injections

    Hey!

    I'm not good with security (lol), what do I need to do to secure my forums that put data into sql databases?

    To stop sql injections, html etc?

    Can somebody find me a tut or write the code with where it goes? I've used google, no use. I had it before, but the link is dead.

  2. #2
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Hitman View Post
    Hey!

    I'm not good with security (lol), what do I need to do to secure my forums that put data into sql databases?

    To stop sql injections, html etc?

    Can somebody find me a tut or write the code with where it goes? I've used google, no use. I had it before, but the link is dead.
    Use a cleaning function

    PHP Code:
    <? 
    function clean($str)
    {
    $cl strip_tags(addslashes(stripslashes(htmlspecialchars($str))));
    return 
    $cl;
    }
    Then use the cleaning string when declaring vars.

    eg

    $v1 = clean($_GET[v1]);
    Coming and going...
    Highers are getting the better of me

  3. #3
    Join Date
    Jun 2006
    Posts
    4,832
    Tokens
    0

    Latest Awards:

    Default

    Thanks!

  4. #4
    Join Date
    Apr 2006
    Location
    Leamington Spa
    Posts
    1,375
    Tokens
    72

    Latest Awards:

    Default

    mysql_real_escape_string() is the best thing to help you with this, but make sure you're connected to a database first or it won't work.
    I.e:
    PHP Code:
    include something.php;
    $var $_POST['var'];
    $newvar mysql_real_escape_string($var); 
    i've been here for over 8 years and i don't know why

  5. #5
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    Dont mean to sound stupid, but what does mysql_real_escape_string do anyways ?

    Like does it filter out commands or something?
    Coming and going...
    Highers are getting the better of me

  6. #6
    Join Date
    Aug 2006
    Location
    Manchester, UK
    Posts
    2,016
    Tokens
    141
    Habbo
    florx

    Latest Awards:


  7. #7
    Join Date
    Sep 2006
    Location
    Hobart, Australia
    Posts
    593
    Tokens
    0

    Default

    I'd suggest using sprintf as well:

    PHP Code:
    $query sprintf("SELECT * FROM users WHERE username='%s'"mysql_real_escape_string($_POST['username']);
    $query mysql_query($query); 
    That tells PHP beforehand what the string should look like, thus preventing injections somewhat.

    Also, don't throw strip_tags, htmlspecialchars and mysql_real_escape_string into the one clean function. Make two; one for sanitizing and one for returning. Sanitizing will apply to all data going into the database (just need mysql_real_escape_string), and returning for data being echoed back to the user (htmlspecialchars imo, no need to strip the tags, just display everything back). You'll find yourself using a load of server resources if you echo everything back using mysql_real_escape_string.

  8. #8
    Join Date
    Jun 2006
    Posts
    4,832
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Beau View Post
    I'd suggest using sprintf as well:

    PHP Code:
    $query sprintf("SELECT * FROM users WHERE username='%s'"mysql_real_escape_string($_POST['username']);
    $query mysql_query($query); 
    That tells PHP beforehand what the string should look like, thus preventing injections somewhat.

    Also, don't throw strip_tags, htmlspecialchars and mysql_real_escape_string into the one clean function. Make two; one for sanitizing and one for returning. Sanitizing will apply to all data going into the database (just need mysql_real_escape_string), and returning for data being echoed back to the user (htmlspecialchars imo, no need to strip the tags, just display everything back). You'll find yourself using a load of server resources if you echo everything back using mysql_real_escape_string.
    OK, so for everything put the mysql_real_escape_string, for things like signature etc put the htmlspecialchars (so no redirections etc).

  9. #9
    Join Date
    Sep 2006
    Location
    Hobart, Australia
    Posts
    593
    Tokens
    0

    Default

    Quote Originally Posted by Hitman View Post
    OK, so for everything put the mysql_real_escape_string, for things like signature etc put the htmlspecialchars (so no redirections etc).
    Pretty much. Thing is, you mightn't want to remove HTML from certain things, like news posts and stuff. That's why you don't want it all in the same function

  10. #10
    Join Date
    Jun 2006
    Posts
    4,832
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Beau View Post
    Pretty much. Thing is, you mightn't want to remove HTML from certain things, like news posts and stuff. That's why you don't want it all in the same function
    You're 2 steps ahead of me.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •