Computing.Net > Forums > Web Development > Protecting PHP file access

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Protecting PHP file access

Reply to Message Icon

Name: RTAdams89
Date: May 23, 2008 at 23:20:29 Pacific
OS: na
CPU/Ram: na
Product: na
Comment:

I am building a PHP application. As part of that, I stored all of the frequently used variables (such as the MySQL database login information) in a file called "config.php" and then simply put "include 'config.php';" at the beginning of each page that needs the database info.

Is it possible for an attacker to put a PHP file on their server which contains "include 'http://myserver.com/config.php';" and then echo out all the variables contained in config.php?

If so, these is a major security hole. How do I protect against such an attack?

-Ryan Adams
http://RyanTAdams.com



Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: May 24, 2008 at 12:32:18 Pacific
Reply:

No, you cannot "include" a file on a separate domain like that. If you tried to include a php file on another domain that file is being requested through that web server and the onlly thing you would be including is the output of that file.

For example, if the included PHP file had an echo statement then the externally requesting page would only see the output of that echo.

Example include file:

<?php
echo "exit;";
?>

If a local page included that file it would "print" the test "exit;" to the page. If an external page tried to include it it would just see "exit;" as the content and would exit the script.

Michael J


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Protecting PHP file access

How to protect PHP includes? www.computing.net/answers/webdevel/how-to-protect-php-includes/1029.html

PHP File Downloader? www.computing.net/answers/webdevel/php-file-downloader/1934.html

Getting IP ón email thru PHP scrip www.computing.net/answers/webdevel/getting-ip-n-email-thru-php-scrip/2070.html