cgm225 Posted May 27, 2007 Share Posted May 27, 2007 When using the following code to connect to a databse:: $DB_host = "localhost"; $DB_user = "my_user_name"; $DB_password = "my_password"; $DB_name = "my_database"; mysql_connect($DB_host,$DB_user,$DB_password) or die("Couldn't connect to the database."); mysql_select_db($DB_name) or die("Couldn't select the database"); Is there anyway to keep the username and password encrypted in the actual php script, like with MD5, or something like that? I ask, because I would like it to be hidden if I have someone else review my code. Thank you all in advance! Quote Link to comment https://forums.phpfreaks.com/topic/53183-encrypting-database-usernamepassword/ Share on other sites More sharing options...
trq Posted May 27, 2007 Share Posted May 27, 2007 Not without going to some expense. There are PHP encrypters out there such as sourceguardian. Quote Link to comment https://forums.phpfreaks.com/topic/53183-encrypting-database-usernamepassword/#findComment-262728 Share on other sites More sharing options...
textbox Posted May 27, 2007 Share Posted May 27, 2007 The way i get around that is to use an include file on any php script needing database access. Keep your connection string as it is and copy it over to another file, and name that file global.php or something similar. At the top of everypage (however, underneath if you are using sessions or anything else header related) call in the connection string using include_once ("global.php"); And your database will connect, leaving you free to give the script to whomever you wish. I tend to keep my included scripts in an include folder, in which case I am including /include/global.php Hope this helps and is what you were looking for Nick Quote Link to comment https://forums.phpfreaks.com/topic/53183-encrypting-database-usernamepassword/#findComment-262731 Share on other sites More sharing options...
chronister Posted May 27, 2007 Share Posted May 27, 2007 Here is the way I do it. In an included file create a function called connectdb() (or whatever you wanna call it.) include.php <?php /////////////////////////////// // connectdb // /////////////////////////////// function connectdb() { mysql_connect('HOST', 'USERNAME', 'PASSWORD'); mysql_select_db('DATABASENAME') or die('Unable to select local database!'); } ?> This include file is included in all my pages by way of the template structure I have set up. Then anytime I need to initiate a connection, I simply call connectdb(); This way I can make a connection easily and it is separate from the rest of the code. <?php connectdb(); $query="INSERT INTO tests (testname,questions)VALUES('$testname','$number_questions')"; $result=mysql_query($query); ?> Quote Link to comment https://forums.phpfreaks.com/topic/53183-encrypting-database-usernamepassword/#findComment-262777 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.