1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Securing PHP/MySQL...

Discussion in 'PHP' started by killaklown, Nov 9, 2007.

  1. #1
    How do i secure data when:

    - Getting It from the database. (ie login)
    - Putting it into the database. (ie registration)

    I already have the passwords in md5.
     
    killaklown, Nov 9, 2007 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    use SSL

    Regards

    Alex
     
    kmap, Nov 9, 2007 IP
  3. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #3
    Im not talking about ssl.

    Edit: double post.. DP was acting weird and it got posted twice.
     
    killaklown, Nov 9, 2007 IP
  4. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #4
    Not talking about SSL, im talking about code to make my php safer...

    This is what i currently have (for my registration page)

    
    $fullname = mysql_real_escape_string($_POST['fullname']);
    $address1 = mysql_real_escape_string($_POST['address1']);
    $address2 = mysql_real_escape_string($_POST['address2']);
    $city = mysql_real_escape_string($_POST['city']);
    $state = mysql_real_escape_string($_POST['state']);
    $country = mysql_real_escape_string($_POST['country']);
    $zip = mysql_real_escape_string($_POST['zip']);
    $email = mysql_real_escape_string($_POST['email']);
    $password = md5(mysql_real_escape_string($_POST['password']));
    $confirmpassword = md5(mysql_real_escape_string($_POST['confirmpassword']));
    $paypal = mysql_real_escape_string($_POST['paypal']);
    $tos= (isset($_POST['tos']))   ? 'Yes' : 'No';
    $old= (isset($_POST['old']))   ? 'Yes' : 'No';
    
    PHP:
     
    killaklown, Nov 9, 2007 IP
  5. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #5
    use localhost as ur dbhost

    regards

    Alex
     
    kmap, Nov 9, 2007 IP
  6. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #6
    What are you talking about?

    Im not asking how to connect to a database!

    Your 'answers' are not even close to what im asking.
     
    killaklown, Nov 9, 2007 IP
  7. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #7
    in phpmyadmin donot allow any other host to connect to db other than localhost

    Also be polite with me


    Regards

    Alex
     
    kmap, Nov 9, 2007 IP
  8. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #8

    Are you actually reading my question?
     
    killaklown, Nov 9, 2007 IP
  9. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #9
    yes i do you have not explained what knd of security u need and why ,what lack of security you feel .So that i can better understand your problem and advise you.

    Regards
    Alex
     
    kmap, Nov 9, 2007 IP
  10. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #10
    Why do i want high security? Because the site will be dealing with cash, I dont want anyone getting into the database, stealing personal information, etc. Not sure why I had to say why i wanted security, would think thats pretty obvious for any website.

    The only security im talking about is php (inserting information into mysql and reading information from the mysql)

    ie:
    mysql_real_escape_string
     
    killaklown, Nov 9, 2007 IP
  11. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #11
    <?php
    function quote_smart($value = "", $nullify = false, $conn = null) {
    //reset default if second parameter is skipped
    $nullify = ($nullify === null) ? (false) : ($nullify);
    //undo slashes for poorly configured servers
    $value = (get_magic_quotes_gpc()) ? (stripslashes($value)) : ($value);

    //check for null/unset/empty strings (takes advantage of short-circuit evals to avoid a warning)
    if ((!isset($value)) || (is_null($value)) || ($value === "")) {
    $value = ($nullify) ? ("NULL") : ("''");
    }
    else {
    if (is_string($value)) {
    //value is a string and should be quoted; determine best method based on available extensions
    if (function_exists('mysql_real_escape_string')) {
    $value = "'" . (((isset($conn)) && (is_resource($conn))) ? (mysql_real_escape_string($value, $conn)) : (mysql_real_escape_string($value))) . "'";
    }
    else {
    $value = "'" . mysql_escape_string($value) . "'";
    }
    }
    else {
    //value is not a string; if not numeric, bail with error
    $value = (is_numeric($value)) ? ($value) : ("'ERROR: unhandled datatype in quote_smart'");
    }
    }
    return $value;
    }
    ?>
     
    kmap, Nov 9, 2007 IP
  12. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #12
    Note: If magic_quotes_gpc is enabled, first apply stripslashes() to the data. Using this function on data which has already been escaped will escape the data twice.

    Note: If this function is not used to escape data, the query is vulnerable to SQL Injection Attacks.
     
    kmap, Nov 9, 2007 IP
  13. bobb1589

    bobb1589 Peon

    Messages:
    289
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #13
    good luck getting help being ignorant like that...
     
    bobb1589, Nov 9, 2007 IP
  14. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #14
    Kmap, you made me laugh for 10 minutes. You should read the post before you answer.



     
    baris22, Nov 9, 2007 IP
  15. armatik

    armatik Peon

    Messages:
    27
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #15
    You should limit the type of data that each goes through. For example, in zip, you probably want to make sure that it's an integer. As for the password, you probably would want to hash it with a salt, and I'm almost sure that you don't need to escape the string if you're hashing it anyway. And you could use some regular expressions to really make it strict, if you seriously feel the need to make this as secure as you possibly can. If it has to do with money and transactions, I'd say be as safe as you can.

    Also, I think you would want to set a limit here, as well as in your form, since someone could use an remote form to just spam your database with useless ..well, spam.
     
    armatik, Nov 9, 2007 IP
  16. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #16
    isnt integer just numbers? If it is, Canadian Zip/Postal codes contain numbers, letters and a space.

    And im going to add a Captcha to the form.
     
    killaklown, Nov 9, 2007 IP
  17. armatik

    armatik Peon

    Messages:
    27
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #17
    What you could also do is you could automatically assign a 'guest' session ID to everyone that goes on your website, and then in the form, create a hidden input that's something like:

    <input type="hidden" value="'. $_SESSION['id'] .'" />
    HTML:
    And then, in your processor file, check that the current session id of the user accessing that processor page is the same as the posted session id. This will prevent people from using remote forms.
     
    armatik, Nov 9, 2007 IP
    killaklown likes this.
  18. omgitsfletch

    omgitsfletch Well-Known Member

    Messages:
    1,222
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    145
    #18
    Whoa whoa, hidden input fields? Terrible idea.

    You'll probably want to have extreme amounts of verification on any data passed to/from the database, and I would try and avoid GET/POST so that users can't manipulate URLs. Sessions are a good idea.
     
    omgitsfletch, Nov 9, 2007 IP
  19. armatik

    armatik Peon

    Messages:
    27
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #19
    I don't see why using POST and hidden input fields is a terrible idea. If the session IDs don't match up, then that means that they're not using the form from his website, therefore disallowing it. The only way the IDs can match up is if they're on that site for both the form submission and processing.
     
    armatik, Nov 9, 2007 IP
  20. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #20
    why kmap the wise thinker didnt reply?? hahahaha,,

    his replies are way to funny, hihihihihii
     
    bartolay13, Nov 9, 2007 IP