0

PHP is a mystery for me. In the FTP main directory of my website, I uploaded 2 files: a.txt and b.txt. If I enter my website address in my browser I can view both a.txt and b.txt. However when I upload a file named index.php or default.php, I can only see a blank page when I refresh my browser.

How does it work and is it enough to keep my files inaccessible?

  • I'm not sure what the question is you are asking. To keep files secure you'll need to protect it somehow on your webserver perhaps via password protected directory or a login script made with php. That way you can keep all your files secure within that directory even php, txt etc. – Abu Nooh Dec 25 '14 at 23:18
1

You have some learning to do. Your server is showing your ".txt" files because it's probably defaulting to serving plain text. When you put ".php" files in there, those are program files that need translating into something the server can serve to the browser. It won't happen by itself.

You need to learn how to set up your server configuration files. Your hosting company may have tutorials on that. Try and find out what kind of server you have, such as Apache. Then Google for things about configuring Apache to serve PHP.

At least that might give you a starting point.

| improve this answer | |
0

Web server software typically can be configured to look for a specific file or files in a directory to display to the browser if the browser isn't requesting a specific file from a directory. E.g., let's suppose your website is accessible via www.example.com. When the web server sees a request for www.example.com/a.txt, it will display the contents of a.txt. But, if it receives a request for just www.example.com, which is a request for the root directory for your website, the web server is likely configured to look for certain types of files, which may be index.html, index.php, and it seems in your case default.php. If it doesn't see them, it will show a listing of all the files in that directory, e.g., a.txt and b.txt, unless it is configured to not show such file listings, which is often the case for security reasons.

But, if index.php is in that directory, it will display the contents of that file. If you put some text in the index.php file, do you see it displayed? Below is a very simple page you could create using a PHP command to display "hello world".

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php echo '<p>Hello World</p>'; ?> 
 </body>
</html>

If you upload that to your site, do you see "hello world" displayed? If not, there is likely a problem with PHP on your web server. You can also create a PHP file with just the line below in it and nothing else and upload it to your site. If PHP is working properly for your website, it should display the version of PHP installed on the web server as well as a lot of other information regarding PHP on the server. You can name the file testing.php or whatever you like. It wouldn't be a good idea to name it index.php and leave it in place for random people on the Internet to view that information, though, since it provides a lot of detail regarding the configuration of the web server used for your site.

<?php phpinfo(); ?>

If you don't see anything displayed, then PHP may not be installed on the server or may not be properly configured for use by your website.

If your purpose for putting the PHP file there is so that people can't see that you have a.txt and b.txt in that directory, then it does prevent them from seeing the list of files in the directory. However, if they know a.txt and b.txt are in that directory they can access them from www.example.com/a.txt, etc.

If you want to learn PHP, you can find tutorials online for free. E.g. PHP 5 Tutorial. You can also take online video courses for free at whatever time is convenient for you and at your own pace. Udemy offers free and relatively low-cost video courses that cover PHP. E.g. PHP & MySQL - PHP & MySQL for Beginners is free as is Beginner PHP and MySQL Tutorial. You can also take a free PHP course through Codecademy at PHP.

| improve this answer | |
0

If you do not want to show the content of a directory/folder when an index file does not exist you can configure the web server to disallow directory listing/indexing/browsing. For example, in Apache https://wiki.apache.org/httpd/DirectoryListings

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy