Need to hide login info - help please

Status
Not open for further replies.

Kd_91

New Member
Messages
7
Reaction score
0
Points
0
Hey guys, I have a little problem. I'm making a new website using PHP and MySQL. On my page, I don't want the MySQL login information to connect to the MySQL database viewable when visitors view the page source.

Here is my exact set up, only the names and everything else is renamed to random joke stuff:

PHP:
<HTML>
<HEAD>
<TITLE> Our List of Jokes </TITLE>
<HEAD>
<BODY>
<?php

  // Connect to the database server
  $dbcnx = @mysql_connect("localhost",
           "root", "mypasswd");
  if (!$dbcnx) {
    echo( "<P>Unable to connect to the " .
          "database server at this time.</P>" );
    exit();
  }

  // Select the jokes database
  if (! @mysql_select_db("jokes") ) {
    echo( "<P>Unable to locate the joke " .
          "database at this time.</P>" );
    exit();
  }

?>
<P> Here are all the jokes in our database: </P>
<BLOCKQUOTE>

<?php
  
  // Request the text of all the jokes
  $result = mysql_query(
            "SELECT JokeText FROM Jokes");
  if (!$result) {
    echo("<P>Error performing query: " .
         mysql_error() . "</P>");
    exit();
  }

  // Display the text of each joke in a paragraph
  while ( $row = mysql_fetch_array($result) ) {
    echo("<P>" . $row["JokeText"] . "</P>");
  }

?>

</BLOCKQUOTE>
</BODY>
</HTML>

As you can see, someone views the page source and has the location, user, and password for the MySQL database written right there for them, how can I change or hide this?

Thanks in advance!
 

knightcon

New Member
Messages
69
Reaction score
0
Points
0
The login information wont be shown in the outputted source code. PHP only outputs HTML, not the programming you do. On top of this it is a security risk putting your MySQL login information in the publicly accessible directory. What you should do is create a new file named something like mysql.vars.php or something to that effect and put it outside the publicly accessible drive. Then just include it in the public file using the include() statement.
 

Kd_91

New Member
Messages
7
Reaction score
0
Points
0
Ok, I didn't even realize that! thanks!

But, umm, the include() statement... is that Javascript? Or have an example of it?
 

Synkc

Active Member
Messages
1,765
Reaction score
0
Points
36
As mentioned, PHP is server side code; it is prosessed before any output is transmitted to the end user. Anything within the "<?php" and "?>" will not be shown to the user, unless using a function like echo() or print().

The include() is a function in PHP, used to 'include' the content of one script into another. For example, you could use this:

PHP:
include("path/to/scirpt/you/are/including");

*It uses paths, not urls; unless specified in the php.ini file.
 
Status
Not open for further replies.
Top