Bluehost.com Web Hosting $6.95

Hiding MySQL username and password

This is a discussion on Hiding MySQL username and password within the MySQL Database forums, part of the Database Forums category; Ok, I am a newbie. But now I have tried everything. My quest is to put the MySQL host name, ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-27-2007
Nosferatum
 
Posts: n/a
Default Hiding MySQL username and password

Ok, I am a newbie. But now I have tried everything. My quest is to put
the MySQL host name, user name, password, databasename and table-name
in a separate file outside our web domain and call these variables via
include (into my PHP-file).
But it wont work! The path & diectories are all fine, the PHP script
works perfect (at last before I decided to move this critical
information).

This is the script:
<?php //starts here...
include ("/home/secret/protect/the_imported_mysqldata.inc");
$link=LinkUp($host,$username,$password)or die("Cant connect");
mysql_select_db($db_name)or die("cant choose db");

$sql="SELECT secret_variable FROM $tbl_name WHERE username='$username'
AND password='$password'";
$result=mysql_query($sql);

(and so on)

here is the included "the_imported_mysqldata.inc":
<?php
$host="the.secret.host";
$username="secret_as_stone";
$password="very_secret";
$db_name="secret_db";
$tbl_name="the_actual_table";

function LinkUp($host,$username,$password)
{
$mysql_link=mysql_connect($host,$username,$passwor d);
return $mysql_link;
}
?>

What have I done wrong? Please??

Reply With Quote
  #2 (permalink)  
Old 03-28-2007
Willem Bogaerts
 
Posts: n/a
Default Re: Hiding MySQL username and password


> here is the included "the_imported_mysqldata.inc":
> <?php
> $host="the.secret.host";
> $username="secret_as_stone";


What happens if you use the require statement instead of include? If it
still does not want to connect, but does include the file, try using the
$GLOBALS array (like: $GLOBALS['host'] = 'the.secret.host';).

Best regards,
--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/
Reply With Quote
  #3 (permalink)  
Old 03-28-2007
Sean
 
Posts: n/a
Default Re: Hiding MySQL username and password


"Nosferatum" <John.Olav.O@gmail.com> wrote in message
news:1175027060.627223.175550@n59g2000hsh.googlegr oups.com...
> Ok, I am a newbie. But now I have tried everything. My quest is to put
> the MySQL host name, user name, password, databasename and table-name
> in a separate file outside our web domain and call these variables via
> include (into my PHP-file).
> But it wont work! The path & diectories are all fine, the PHP script
> works perfect (at last before I decided to move this critical
> information).
>
> This is the script:
> <?php //starts here...
> include ("/home/secret/protect/the_imported_mysqldata.inc");
> $link=LinkUp($host,$username,$password)or die("Cant connect");
> mysql_select_db($db_name)or die("cant choose db");
>
> $sql="SELECT secret_variable FROM $tbl_name WHERE username='$username'
> AND password='$password'";
> $result=mysql_query($sql);
>
> (and so on)
>
> here is the included "the_imported_mysqldata.inc":
> <?php
> $host="the.secret.host";
> $username="secret_as_stone";
> $password="very_secret";
> $db_name="secret_db";
> $tbl_name="the_actual_table";
>
> function LinkUp($host,$username,$password)
> {
> $mysql_link=mysql_connect($host,$username,$passwor d);
> return $mysql_link;
> }
> ?>
>
> What have I done wrong? Please??
>



I am probably mistaken, but do you need to have "<?php" and "?>" in the
include file, as the file will be included within a section of code that's
already wrapped in the start/end php codes?



Reply With Quote
  #4 (permalink)  
Old 03-28-2007
strawberry
 
Posts: n/a
Default Re: Hiding MySQL username and password

On Mar 28, 4:23 pm, "Sean" <sean.anderson@[nospam]oakleafgroup.biz>
wrote:
> "Nosferatum" <John.Ola...@gmail.com> wrote in message
>
> news:1175027060.627223.175550@n59g2000hsh.googlegr oups.com...
>
>
>
> > Ok, I am a newbie. But now I have tried everything. My quest is to put
> > the MySQL host name, user name, password, databasename and table-name
> > in a separate file outside our web domain and call these variables via
> > include (into my PHP-file).
> > But it wont work! The path & diectories are all fine, the PHP script
> > works perfect (at last before I decided to move this critical
> > information).

>
> > This is the script:
> > <?php //starts here...
> > include ("/home/secret/protect/the_imported_mysqldata.inc");
> > $link=LinkUp($host,$username,$password)or die("Cant connect");
> > mysql_select_db($db_name)or die("cant choose db");

>
> > $sql="SELECT secret_variable FROM $tbl_name WHERE username='$username'
> > AND password='$password'";
> > $result=mysql_query($sql);

>
> > (and so on)

>
> > here is the included "the_imported_mysqldata.inc":
> > <?php
> > $host="the.secret.host";
> > $username="secret_as_stone";
> > $password="very_secret";
> > $db_name="secret_db";
> > $tbl_name="the_actual_table";

>
> > function LinkUp($host,$username,$password)
> > {
> > $mysql_link=mysql_connect($host,$username,$passwor d);
> > return $mysql_link;
> > }
> > ?>

>
> > What have I done wrong? Please??

>
> I am probably mistaken, but do you need to have "<?php" and "?>" in the
> include file, as the file will be included within a section of code that's
> already wrapped in the start/end php codes?


Yes you are - and yes you do! Correct me if I'm wrong but I think the
file server also needs permission to read the folder in which the
include is buried.
I know nothing whatsoever about security but I would have thought that
just putting the includes in a folder just outside the htdocs path
would be safe enough.

The folder would not need to be called anything like 'include'.
Likewise, I think the file can have any extension you care to give it

Reply With Quote
  #5 (permalink)  
Old 03-28-2007
John Nagle
 
Posts: n/a
Default Re: Hiding MySQL username and password

strawberry wrote:
> On Mar 28, 4:23 pm, "Sean" <sean.anderson@[nospam]oakleafgroup.biz>
> wrote:
>
>>"Nosferatum" <John.Ola...@gmail.com> wrote in message
>>
>>news:1175027060.627223.175550@n59g2000hsh.google groups.com...
>>
>>
>>
>>
>>>Ok, I am a newbie. But now I have tried everything. My quest is to put
>>>the MySQL host name, user name, password, databasename and table-name
>>>in a separate file outside our web domain and call these variables via
>>>include (into my PHP-file).


> I know nothing whatsoever about security

Um.

> but I would have thought that
> just putting the includes in a folder just outside the htdocs path
> would be safe enough.


The problem is that the web server, usually Apache, runs CGI programs
as user "nobody". It can't read your non-public files. If you
make the password file readable by any user,
anybody else on the machine can read it, which is terrible in shared
server environments.

John Nagle
Reply With Quote
  #6 (permalink)  
Old 03-28-2007
strawberry
 
Posts: n/a
Default Re: Hiding MySQL username and password

On Mar 28, 9:00 pm, John Nagle <n...@animats.com> wrote:
> strawberry wrote:
> > On Mar 28, 4:23 pm, "Sean" <sean.anderson@[nospam]oakleafgroup.biz>
> > wrote:

>
> >>"Nosferatum" <John.Ola...@gmail.com> wrote in message

>
> >>news:1175027060.627223.175550@n59g2000hsh.google groups.com...

>
> >>>Ok, I am a newbie. But now I have tried everything. My quest is to put
> >>>the MySQL host name, user name, password, databasename and table-name
> >>>in a separate file outside our web domain and call these variables via
> >>>include (into my PHP-file).

> > I know nothing whatsoever about security

>
> Um.
>
> > but I would have thought that

>
> > just putting the includes in a folder just outside the htdocs path
> > would be safe enough.

>
> The problem is that the web server, usually Apache, runs CGI programs
> as user "nobody". It can't read your non-public files. If you
> make the password file readable by any user,
> anybody else on the machine can read it, which is terrible in shared
> server environments.
>
> John Nagle


So what's the correct solution?

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:57 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0