SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    May 2011
    Posts
    191
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Hidding MySQL connection data

    Good day,

    In order to avoid undesired access to sensible information of database connection (name, password, ...) , I was suggested to create a new .php file and save it in a directory out of the root, where is unaccessible to web users.
    I did it, and now I have to include this file in all .php files needing to connect to MySQL database.

    My question is, how can I refer this directory where the "password" file is?
    In other words, how is the syntaxis of the line to refer it (to write the include sentence)?

    Here the directories:
    php_library (where the file with the password information is)
    www (website root)
    spanish (where the .php files are, referring the "password"file through an onclude sentence)


    Thanks a lot!!!!

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,607
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    ../php_library
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Addict sdleihssirhc's Avatar
    Join Date
    Feb 2009
    Posts
    387
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Let's say you have the following file structure:

    Code:
    php_library
        db.php
    www
        index.php
    In your index.php file, you would just use "include" as you normally would:

    PHP Code:
    include '../php_library/db.php'
    Just because the user can't access the folder, doesn't mean PHP can't see it.

    If you wanted, you could use an absolute path, instead:

    PHP Code:
    include 'full/absolute/path/to/php_library/db.php'
    And if you're not sure of the absolute path, you can use the __FILE__ magic constant:

    PHP Code:
    echo __FILE__// echos the full path and filename of the current file 
    I'm the web overlord for Graphic Business Systems

  4. #4
    SitePoint Zealot
    Join Date
    May 2011
    Posts
    191
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    This website has been developed using HTML/CSS, so I dont have an index.php file ... but an index.html one ...
    The first .php file is under www/spanish folder

    Should I then add this include sentence in this .php file?

    Thanks a lot!!!!

  5. #5
    SitePoint Member
    Join Date
    Dec 2004
    Location
    laval
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    shortest answer is the include in that php file ../../php_library/db.php but it might be smarter to use full path so that you can move that file around and not worry about editing it in the future

  6. #6
    SitePoint Zealot
    Join Date
    May 2011
    Posts
    191
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Yes, I tried with this sentence:
    include '../../php_library/database.php';

    Is is properly written? I got an error message:
    Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/libroman/public_html/spanish/dsstgo.php on line 13

    Thanks a lot!!

  7. #7
    SitePoint Zealot
    Join Date
    May 2011
    Posts
    191
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It's all fine now. It was my mistake!!!

    Thanks a lot!!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •