Code Help (kinda) - Need To Hide Login Info

Discussion in 'Gaming' started by killer_kyle, Dec 13, 2007.

  1. killer_kyle

    killer_kyle Well-Known Member

    Posts:
    365
    Likes Received:
    0
    Joined:
    Aug 2, 2006
    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 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:

    Code:
    <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( "
    
    Unable to connect to the " .
              "database server at this time.</P>" );
        exit();
      }
    
      // Select the jokes database
      if (! @mysql_select_db("jokes") ) {
        echo( "
    
    Unable to locate the joke " .
              "database at this time.</P>" );
        exit();
      }
    
    ?>
    
    
     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("
    
    Error performing query: " .
             mysql_error() . "</P>");
        exit();
      }
    
      // Display the text of each joke in a paragraph
      while ( $row = mysql_fetch_array($result) ) {
        echo("
    
    " . $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!
     
  2. killer_kyle

    killer_kyle Well-Known Member

    Posts:
    365
    Likes Received:
    0
    Joined:
    Aug 2, 2006
    Nvm I figured it out
     
  3. TomParad0x

    TomParad0x Well-Known Member

    Posts:
    235
    Likes Received:
    0
    Joined:
    Feb 24, 2006
    Just to comment on this (Even if you figured it out):

    I don't see why it would be. PHP is processed server-side, none of that PHP on the page would be sent to the browser, and would not be in the source on a loaded webpage..
     
  4. killer_kyle

    killer_kyle Well-Known Member

    Posts:
    365
    Likes Received:
    0
    Joined:
    Aug 2, 2006

    yeah thanks, thats what I figured out

    Im so dumb jeez...

    Thanks for reply anyways :)
     
  5. TomParad0x

    TomParad0x Well-Known Member

    Posts:
    235
    Likes Received:
    0
    Joined:
    Feb 24, 2006
    No problem :)

    If you need any other PHP code help feel free to ask me :)

    My job is coding PHP portion websites atm.
     

Share This Page