sir_arcturua — 2011-10-28T16:15:42-04:00 — #1
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!!!!
felgall — 2011-10-28T17:55:11-04:00 — #2
sdleihssirhc — 2011-10-28T17:56:46-04:00 — #3
Let's say you have the following file structure:
In your index.php file, you would just use "include" as you normally would:
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:
And if you're not sure of the absolute path, you can use the FILE magic constant:
echo __FILE__; // echos the full path and filename of the current file
sir_arcturua — 2011-11-01T10:47:13-04:00 — #4
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!!!!
markedagain — 2011-11-01T10:56:51-04:00 — #5
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
sir_arcturua — 2011-11-01T11:28:41-04:00 — #6
Yes, I tried with this sentence:
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!!
sir_arcturua — 2011-11-01T12:00:17-04:00 — #7
It's all fine now. It was my mistake!!!
Thanks a lot!!!