portia Posted July 19, 2009 Share Posted July 19, 2009 Hi everyone, I'm a newbie when it comes to php. I've been playing with it for the last 2 weeks. Which one is recommended as a root document: index.php or index.html (with pieces of php code embedded inside). When would you use which one? thanks Quote Link to comment Share on other sites More sharing options...
haku Posted July 19, 2009 Share Posted July 19, 2009 It really doesn't matter one way or another. But, you will find that almost no servers are configured to read php in an .html document. You need to configure it yourself to be able to do that. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 19, 2009 Share Posted July 19, 2009 I think his asking, if you went to a folder that has a index.php and a index.html in it and you just went to that folder (not the file) which one would load by default.. Well that does depend on how apache was configured, best bet is just to try it if your asking is it better to have a index.php or index.html then I always create index.php as it allows me to add code without worrying about if i have a link pointing to index.html Quote Link to comment Share on other sites More sharing options...
portia Posted July 19, 2009 Author Share Posted July 19, 2009 Thanks guys, I know how to configure apache to read .php or .html. My question was which one you normally use as the index. It really doesn't matter one way or another. But, you will find that almost no servers are configured to read php in an .html document. You need to configure it yourself to be able to do that. Doesn't mind to me, mine reads both index.html (with php inside) or index.php. So you're saying that either way is ok. if your asking is it better to have a index.php or index.html then I always create index.php as it allows me to add code without worrying about if i have a link pointing to index.html due to the above mentioned reason, you seem to prefer index.php, are there any disadvantages of it? thanks guys. I've started learning php and want to develop good habits right from the beginning. Hence, my elementary questions) Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 19, 2009 Share Posted July 19, 2009 The only disadvantage I can think of would be a VERY VERY slightly slower as it would run via PHP as well.. but that's ever so slight! Quote Link to comment Share on other sites More sharing options...
SuperBlue Posted July 23, 2009 Share Posted July 23, 2009 Remember to include something like the below in the top of the script, to prevent having the same content indexed on both the index.php file, as well as the domain it self. if ($_SERVER['REQUEST_URI'] == '/index.php') { header('HTTP/1.1 404 Not Found'); include_once '404.php'; /* mysql_close($Connection); // include if you use MySQL */ exit(); } Sample 404 page: <!DOCTYPE html> <html lang="en"> <head> <title>404 Not Found</title> <meta name="robots" content="noindex,nofollow"> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"> <style type="text/css"> </style> </head> <body> <h1>404 Not Found</h1> <p>Nothing was found on the specified location:</p> <p><?php echo htmlentities($_SERVER['REQUEST_URI']); ?></p><p><a href="/">Frontpage</a></p> </body> </html> Quote Link to comment Share on other sites More sharing options...
portia Posted July 23, 2009 Author Share Posted July 23, 2009 BlueBoden, could you elaborate on it a bit? I am afraid I don't know where I'm supposed to include it (in index.php?)? sorry, just starting thanks Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 23, 2009 Share Posted July 23, 2009 What his saying is IF you have both index.php and index.html, them a search bot may take the contents of both for indexing in search engines, the code basically tell the bot that the page its viewing doesn't exist.. but then again why have a page their at all if its only function is to not exists! Quote Link to comment Share on other sites More sharing options...
bronzemonkey Posted July 25, 2009 Share Posted July 25, 2009 Remember to include something like the below in the top of the script, to prevent having the same content indexed on both the index.php file, as well as the domain it self. Use a 301 redirect. Better for the user and better for any spider. Serving a 404 is a bad idea. Quote Link to comment Share on other sites More sharing options...
vineld Posted July 26, 2009 Share Posted July 26, 2009 There is really no reason why you should have an index.html as start page if your site is built on php. However, like people have already told you, either way will work. Make your life easier though and just go with index.php. SEO-wise, see to that you always link to the domain itself and not to index.php (or index.html), then you will have no duplicate content problems. Quote Link to comment Share on other sites More sharing options...
portia Posted July 26, 2009 Author Share Posted July 26, 2009 Thsnkd guys for your replies. So if I am going to rely on index.php, what's the way of including some formatting (css) file in php? Quote Link to comment Share on other sites More sharing options...
vineld Posted July 26, 2009 Share Posted July 26, 2009 Thsnkd guys for your replies. So if I am going to rely on index.php, what's the way of including some formatting (css) file in php? You'll place all css and html just as you would in the .html file. There's no difference. Quote Link to comment Share on other sites More sharing options...
haku Posted July 26, 2009 Share Posted July 26, 2009 CSS acts on HTML. PHP outputs HTML. CSS doesn't interact with PHP whatsoever. Output your HTML, then set the CSS to act upon it. Quote Link to comment Share on other sites More sharing options...
vineld Posted July 26, 2009 Share Posted July 26, 2009 CSS acts on HTML. PHP outputs HTML. CSS doesn't interact with PHP whatsoever. Output your HTML, then set the CSS to act upon it. Not to pick on you but of course it is possible to output CSS and every other kind of code syntax using PHP as well Quote Link to comment Share on other sites More sharing options...
portia Posted July 26, 2009 Author Share Posted July 26, 2009 Thanks guys. It's making more and more sense. Would it be too much if I asked you to provide an example of index.php that outputs html that links to an external css file? Quote Link to comment Share on other sites More sharing options...
vineld Posted July 26, 2009 Share Posted July 26, 2009 <html> <head> <link rel="stylesheet" type="text/css" href="thisisme.css" /> </head> <body> <h1>Hi there!</h1> </body> </html> You display code in index.php just as you would in index.html or any other file. The only difference is that you're able to execute php code inbetween <?php ?> blocks. You may of course also print html, css or anything else using php as well. The file extension has no meaning other than which extensions you instruct the server to parse as php (or any other language). You may as well have index.google or index.tree parsed as php as well if you wish. Quote Link to comment Share on other sites More sharing options...
haku Posted July 27, 2009 Share Posted July 27, 2009 CSS acts on HTML. PHP outputs HTML. CSS doesn't interact with PHP whatsoever. Output your HTML, then set the CSS to act upon it. Not to pick on you but of course it is possible to output CSS and every other kind of code syntax using PHP as well It sure is. But the CSS doesn't interact with the PHP, it is just outputted by the PHP. It acts on html, which is what I said in my original post. Not to pick on you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.