Question

I am making a PHP script that people will have to purchase.

<?php
    session_start();
    $dbhost = "localhost";
    $dbname = "planeub9_airmanagemembership";
    $dbuser = "planeub9_malcolm";
    $dbpass = "mypassword";

    mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());  
    mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());  
?>

Is there any way that the db password can be hidden from plain view?

Était-ce utile?

La solution

I will start with assuming you would like to release a tarball or zipfile of your software project, rather than granting access to your whole Git repository. To do this, you can use something like git archive to create a release of your project.

Before you do this, you need to ensure that your configuration file is not committed to version control. If it is already, then copy it (for example copy "/config/base.php" to "/config/base.php.example") and reset all the settings to dummy values prior to committing it. Then remove the real config file from version control whilst leaving the physical file on disk.

To prevent this file coming up in your git status as uncommitted, add "/config/base.php" into your ".gitignore" file. This will help prevent you accidentally re-committing it too. Finally, add some instructions in your "README" to explain that "base.php" needs to be created as a copy of "base.php.example".


Now, if you wish to release the whole repo and you have already committed your configuration file, you have two options. Firstly, you can take the above advice about removing it from the repo now, and then change your database credentials. This will leave your private details in the repo, but they will be out-of-date and thus harmless.

Or, you can excise the configuration file from your repo entirely using git rebase. This causes problems if you have pushed the project to other contributors, who will have to pull a fresh copy and re-apply any pending changes. However, to remove something entirely from history, it is unavoidable (and if you let your collaborators know what is going on, quite easy to manage).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top