Re: mysql_connect
| From: | Gorka Valencia | Date: | Mon, 02 Oct 2000 21:13:12 +0000 |
| Subject: | Re: mysql_connect | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-18314@lists.php.net to get a copy of this message | ||
// sorry for my poor english... :(
It might be impossible to view the PHP source from a web browser if your
webserver is properly configured. When you type the xxxx.php file on the browser
URL, it will be passed to the PHP program to be interpreted, so it will never
print the line "mysql_connect(HOST,USER,PASS)" , and the pass will never show in
the browser.
but yes, it's more secure to store that info outside the main program.
you may use an "include" file from anywhere outside the web directory, i.e. on
your root , or a directory where you store all include files...
define some constants or variables in that include file, like this...
<?php
// dbconnect.inc ... @ stored on /user/home/xxxx/
// your web root directory will be /user/home/xxxx/public_html/ or something
like that...
$HOST = "yourhost";
$DB_USER = "user_to_database";
$DB_PASS = "the_password";
?>
-----
then use an include sentence in the connect program...
<?php
// db_connect.php3 ...
// this file may be located at /user/home/xxxx/public_html/php/ , or whenever
include ("/user/home/xxxx/dbconnect.inc");
if ($dblink = mysql_connect($HOST, $DB_USER, $DB_PASS))
echo "success!!!";
else echo "ummmmmm... something wrong...";
?>
---------
I haven't tried this code... but hope it will work.
Hope this will help you..
regards
Gorka Valencia
-----------
Michael Conley wrote:
>
> I am connecting to a MySQL database to retrieve data (or update data). In
> the PHP page I have the connection information (host, username, password).
> Unfortunately, this information is easily read by anyone who views the
> source of my PHP page. How can I make the connection to the MySQL database
> in some other page or otherwise not expose the connection information?