How do I hide my mySQL login info in my php script?

22,982

Solution 1

Create database.php, move your code snippet above to database.php, then ..

include "database.php";

At the top of each page that needs a database connection.

Solution 2

First step: Put all mysql api into separate file, than include it in other scripts.

Second: Deny access to sql config\api file due configuring your server.

btw, whom do you show "show all my security access info"?

Share:
22,982
Erik
Author by

Erik

Christian, Father, Husband, Servant, Runner, SoCal Native, and forgiven, acting on my Faith in Jesus Christ as a new creation on good soil.

Updated on August 26, 2022

Comments

  • Erik
    Erik almost 2 years

    I have a great php mySQL login script that works fine. Is ther another way to provide all my access info without revealing it in the script? Right now I show all my security access info which I think is not safe.

    Can I hide this?

    Here is what I'm referring to:

        $host="localhost"; // Host name
    $username="XXXXXXXXXX"; // Mysql username
    $password="XXXXXXXXXX"; // Mysql password
    $db_name="XXXXXXXXXXX"; // Database name
    $tbl_name="XXXXXXXXXX"; // Table name