| | #1 |
| Active Warrior Join Date: 2009
Posts: 66
Thanks: 33
Thanked 6 Times in 4 Posts
|
Right now I'm trying to build a bunch of sites for my adsense project, but it's been a while since the last time I made a website, and I've gotten a bit rusty. I'll be using php includes for the header and footer. This is the piece of code I used to use, however I'm not sure if it's outdated and therefore poses a safety hazard, or if it's fine and I can go right ahead and use it. So if one of you clever people out there could take a look and tell me how the following piece of code looks, I'd be very thankful.☆〜 PHP Code: |
| |
| | #2 |
| Lisa Dozois War Room Member Join Date: 2006 Location: Florida, USA.
Posts: 608
Thanks: 107
Thanked 254 Times in 118 Posts
|
I don't see a problem with it. What type of security concern did you have? What I do see a problem with is referencing $_SERVER['QUERY_STRING'] without sanitizing it first. |
|
-- Lisa G
| |
| |
| | #3 |
| HyperActive Warrior War Room Member Join Date: 2008 Location: New York
Posts: 156
Thanks: 0
Thanked 24 Times in 20 Posts
|
Looks fine to me, although I usually opt for include_once instead of include.
|
| | |
| |
| | #4 | |
| Active Warrior Join Date: 2009
Posts: 66
Thanks: 33
Thanked 6 Times in 4 Posts
|
If I want to use include_once instead of include, I just add _once to the include already there, right? No need to add more code anywhere else? | |
| |
| | #5 | |
| Software Engineer War Room Member Join Date: 2008 Location: Asheville, NC USA
Posts: 693
Thanks: 37
Thanked 112 Times in 100 Posts
|
You could also use require or require_once, which will throw a fatal error if the content does not exist, or in the latter case, if you attempt to require it twice. Whether you use include, include_once, require, or require_once, just depends on how strict you are being with yourself and your potential to make coding errors. It is also a way of reminding yourself the nature of the content being included. And yes, the syntax is exactly the same as for "include" | |
| I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs | ||
| |
| | #6 | |
| VIP Warrior Join Date: 2005 Location: Potemkin Village
Posts: 1,724
Thanks: 745
Thanked 742 Times in 498 Posts
|
There's something else you might want to be aware of. A couple of questions: What are the contents of the file 'header.php'? And, would you want to give anybody in the world the possibility to see the contents of 'header.php'? As a weird example, let's say 'header.php' includes the lines: ============= $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); $passwords = '../data/passwords.txt'; ============= Whatever is in 'header.php', it will never be seen in most cases. But what happens if there is a problem with the PHP module for your webserver and php files are not executed by the php interpreter? What often can happen is that the PHP files would be sent directly to the browser as plain text, and anybody could see that you have an include for the file 'header.php'. Then, since your server is having trouble and displaying files as plain text instead of executing them, a person could go ahead and direct their browser to 'header.php' and read that file's contents, getting whatever information you don't want them to get. This doesn't often happen, but under heavy load, or due to other problems, it does. You may have gone to a site before and seen, not the output you expected, but the raw PHP code that runs the site. For this reason, it may be good to give include files in your scripts the .inc extension and not the .php extension, and then to use .htaccess (if you're using Apache) to tell apache not to let anybody see the .inc files under any circumstances. You would do it like this: Rename header.php to header.inc Change the relevant include statement from: include('header.php'); to include('header.inc'); Then finally, put something in an .htaccess file that would return a 403 error if anybody tries to access the 'header.inc' file (or any .inc file for that matter). <Files ~ "\.inc$"> Order allow,deny Deny from all Satisfy All </Files> | |
|
:)
| ||
| |
| The Following User Says Thank You to mojojuju For This Useful Post: |
| | #7 |
| Crazy Internet Marketer War Room Member Join Date: 2010 Location: Germany
Posts: 101
Thanks: 1
Thanked 34 Times in 12 Posts
|
Just be careful to only rename the files to *.inc if the .htaccess rule is active, otherwise its even more unsafe than before! I personally never rename *.php files because my whole websites are in PHP so if PHP is not working I have far greater problems than that |
|
** Get my ViralListMachine software now for free and build your own list virally by giving away free stuff @ http://www.virallistmachinegiveaway.com **
| |
| |
| | #8 | |
| Active Warrior Join Date: 2009
Posts: 66
Thanks: 33
Thanked 6 Times in 4 Posts
|
Turns out I don't need to be worried this time around. The content of my PHP files is just plain old HTML - nothing I mind the world seeing. Thanks for the thorough explanation. I'm gonna save it to a text file so, if I ever add more to my php files than just html, I'll know what to do =) | |
| |
| | #9 | |
| Active Warrior Join Date: 2009
Posts: 66
Thanks: 33
Thanked 6 Times in 4 Posts
|
I'm gonna go with just .php for now, and then if I ever need to include sensitive information in the header file, I'll take it from there.. | |
| |
|
| Bookmarks |
| Tags |
| include, php, safe |
| |