-1

I am developing code in PHP. I am creating a website to demonstrate the scripts that use PHP code.

Can someone explain how to structure this project.

I have many pieces (files) to the puzzle but cannot properly congeal them to work.

Launching index.php display “server not found.” Launching index.html displays the correct elements which when clicked correctly navigate to other pages.

My question is asking that someone explain to me logically when the home entry is index.php and when the home entry is index.html?

When I view source from any site it is always and only html code that is visible.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
iHaveAQuestion
  • 301
  • 2
  • 5
  • 14
  • If you have server side processing that needs to be done before the `index` page is rendered (i.e. you need to execute PHP code), then use `index.php`. If you're simplying displaying static HTML, use `index.html`. Two questions: Do you have an `index.php` page? and Is `PHP` installed? – War10ck May 07 '14 at 15:41
  • My guess would be, you didn't have PHP installed. `html` for static and `php` for dynamic page – iamsleepy May 07 '14 at 15:41
  • possible duplicate of [when to use index.php instead of index.html](http://stackoverflow.com/questions/14208930/when-to-use-index-php-instead-of-index-html) – potashin May 07 '14 at 15:42
  • Possible duplicate of http://stackoverflow.com/questions/16192049/how-to-make-apache-serve-index-php-instead-of-index-html – smcjones May 07 '14 at 15:42
  • The question is... what development stack are you using? – phpisuber01 May 07 '14 at 15:43
  • This is not a duplicate. I am drilling down to the basics. – iHaveAQuestion May 07 '14 at 15:51
  • @war10ck okay. I have just edited my comment to respond to you regarding further specifics. – iHaveAQuestion May 07 '14 at 15:53
  • @iamsleepy I have mama installed. – iHaveAQuestion May 07 '14 at 15:53
  • @smcjones thanks. Yes this is helpful and I know that. Still trying to understand the strategy for what I am trying to do. Like why do all websites - when show source code show html. I understand how GET will put info in URL and POST will not....I am confused but not a complete novice. – iHaveAQuestion May 07 '14 at 15:56
  • 1
    @iHaveAQuestion: First, you do not use the question area to write comments to individual users. This is not a chatroom. Comments belong here. Also, when you say “When I view source from any site it is always and only `html` code that is visible.” You are clearly massively in over your head. PHP is a scripting language. HTML is the final product of PHP code created to view a website. If you cannot grasp that, then you need a lot of work understanding how the basics of PHP & HTML interact before you do anything else. – Giacomo1968 May 07 '14 at 16:10

3 Answers3

3

Using .php file tells your web server to run the PHP code using the PHP interpreter. If you use .html it does not run your code through the interpreter.

The reason you only see HTML code when you view source, is PHP is used to decide WHAT to present to the user, you use HTML to decide how you will display that information to the user.

The HTML is given to the browser by the server, so the browser knows how to display the content. The browser does not care about any PHP as PHP is run on the server (server side). HTML is deployed in the browser (client side).

You can of course hide the .php extension, but I feel this is beyond the scope of the answer, if you do not understand what PHP actually is.

EDIT: I assume your using Windows? If so you need to install some kind of WAMP stack (Windows, Apache, Mysql, PHP). Google for one of these. This will install the software necessary to run PHP code.

  • really. Thanks, it is clearing up. I am using MAMP. Installed and configured myself. Been writing php code and testing it by typing in localhost/pathToFolder. A few helpful responses that require me to troubleshoot and experiment to sort it out. Please follow my thread if possible. It may take me a while to update my progress but really - you have helped. how do I provide recognition to users who help even if problem not completely resolved yet ? – iHaveAQuestion May 07 '14 at 16:15
  • If you feel my answer is helpful, but does not yet provide you with the full answer your looking for, you may upvote it. I am unfamiliar with MAMP as I am not a MAC user, so I may not be able to help you when it comes to MAC specific config. I do warn you though, this post may be removed as it does not fit the format of Stack Overflow, it is to generic. We can't provide you with your own personal tutorial, you need to do some more research yourself. Good luck! – EquinoxMatt May 07 '14 at 16:17
  • Nope. I don't need a personal tutorial. Plenty of those online. Please do not remove the post. I have already altered my httpd.conf file - just needed a reminder on that. and the responses above are just perfect to conceptually get the server side - client side techniques of code processing straightened out. If you web search out there, you will notice many such queries posted and the responses here are clearer than the majority which will serve the tech community well in my humble opinion. Back to it :) – iHaveAQuestion May 07 '14 at 16:35
3

I believe the confusion is coming in from the difference between PHP and HTML.

PHP is a server-side language. What that means is that PHP is parsed before an HTML page is loaded. PHP does not need to serve HTML, but it certainly can.

If you have a PHP script, say index.php, and you do this:

<?php
echo "Hello, World!";
?>

What you are actually doing is telling Apache to use PHP's parser to execute this script when a browser initiates a request via HTTP/HTTPS.

The steps go:

  1. Client (browser) calls index.php.
  2. Server (host) parses index.php.
  3. Server (host) returns any HTML (echo spits out whatever is there, so Hello World! is HTML.
  4. Client (browser) receives the HTML.

Output (Source Code client is given by server):

Hello World!

That means each request you make to a PHP file goes through these processes before you even see your browser.

That is why if you create a giant loop it takes a long time for a website to load. The server is not ready to provide the HTML because it is doing calculations.

Apache, when configured to read PHP, typically reads .php files. However, you can hack Apache to have PHP parse any file extension, including .html,.xml, or even .jpg if you wanted.

Community
  • 1
  • 1
smcjones
  • 5,490
  • 1
  • 23
  • 39
  • Please read the above comment to equinoxmatt because it is meant for you too. Really - thanks. Will update. Please keep an eye on my progress if possible. – iHaveAQuestion May 07 '14 at 16:17
2

It depends on how the webserver is configured. For example, the apache uses the dir_module and will look for all files defined as DirectoryIndex in the httpd.conf one after another.

Example httpd.conf (Snippet)

<IfModule dir_module>
    DirectoryIndex index.php index.pl index.cgi index.asp index.shtml index.html index.htm \
                   default.php default.pl default.cgi default.asp default.shtml default.html default.htm \
                   home.php home.pl home.cgi home.asp home.shtml home.html home.htm
</IfModule>

https://httpd.apache.org/docs/current/mod/mod_dir.html

Edit: I think I missinterpreted the question?! Oo

PHP is server-side, while HTML will be rendered on client-side (your browser). So you won't never be able to see others PHP code, which is good for various reasons.

dschu
  • 4,992
  • 5
  • 31
  • 48
  • Please read the above comment to equinoxmatt and am jones because it is meant for you too. Really - thanks. Will update. Please keep an eye on my progress if possible. And I appreciate the reminder about the http.conf file. I have been there in the past and need to modify it to prioritize .php if it is not already. Just need a bit of time to decipher all of this really helpful feedback. – iHaveAQuestion May 07 '14 at 16:20