PHP connect to database file how to link and hide

Discussion in 'PHP' started by xbat, Aug 8, 2011.

  1. #1
    I am a bit new to this.. but I have create a great little login script.. the only thing is I want to hide the info that connects to my database so im not easily hacked.. Example

    <?php
    $db_host = 'localhost';
    $db_user = '';
    $db_pwd = '';

    $database = '';
    $table = '';

    I have this in the top of every file that links to the database.. how would I add in something that would link for example like css? and would also hide it? like one main file that holds the database info?

    thanks
     
    xbat, Aug 8, 2011 IP
  2. dthoai

    dthoai Member

    Messages:
    106
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    38
    #2
    You should move all database infos to a .php file, eg. config.php. In top of every file that links to the database, you add:

    require('config.php');
    Code (markup):
       

    This will reduce security risk. 
     
    dthoai, Aug 8, 2011 IP
  3. xbat

    xbat Well-Known Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    105
    #3
    beautiful.. thank you very much... :)
     
    xbat, Aug 9, 2011 IP
  4. TsubasaOzora

    TsubasaOzora Well-Known Member

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    113
    #4
    TsubasaOzora, Aug 9, 2011 IP
  5. ausrixy

    ausrixy Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #5
    moving all to 1 file makes it easier to change but there is no way to hide that information.
     
    ausrixy, Aug 10, 2011 IP