Donate SIGN UP

php code on html page

Avatar Image
liquoricemad | 17:01 Sat 03rd Sep 2005 | Technology
8 Answers
I'm new to php and trying to insert the date onto my home page. I can do this on a .php page but inserting the same code within the body tags of an html page results in the code being ignored. Would I need to put the server details onto the page? (which I don't want to do, as it involves passwords). Any help would be much appreciated.

Answers

1 to 8 of 8rss feed

Best Answer

No best answer has yet been selected by liquoricemad. Once a best answer has been selected, it will be shown here.

For more on marking an answer as the "Best Answer", please visit our FAQ.
<?php
echo date("l dS of F Y");
?>

Prints : "Saturday 03rd of September 2005"

Check here for the format to print the date in:
http://www.w3schools.com/php/php_date.asp

The above code worked perfectly for me on my server.

Wait a minute - I think I've misread your question. Whichever page you have this code on has to finish ".php".
You can just change this suffix of this page without adding any "server details" to the content of it. The php code only works on pages that end ".php".
Question Author

Thanks, stevie21, that makes it much clearer. I know now not to write any php code to html pages. Does this mean that if I changed the index.html page to index.php, the home page that would load would be index.php? Or would I have to delete the index.html as well?

(So when the address is typed in, the index.php would load automatically?)

thanks, btw, for the link, that was helpful also! 

if you have access to your .htaccess file, you could make the server process .htm pages as .php pages too.

but if you can do that, you should remove all extensions (except for images), and treat all other things as something to be processed by PHP.
Question Author
Thank you, fo3nix, I'll have a look at this, as most of the pages are to be in php format anyway.  I'll let you know how I get on. 
Also make sure that any other files on your site that have links to "index.html" are amended to link, instead, to index.php

All you need to do is just rename this file to end "php" : dead easy if you have ftp access or a "control panel" with your webhost.

If you just type in the address as www.stevie21.com without specifying the filename and you still are sent to the "html" file then all you have to do is amended the file pointed to (or at worst, replace the html file with one that includes a redirect)
Question Author

Thank you, stevie21, I've now uploaded the new .php page, deleted the .html one, and changed all the links leading to the old home page - excellent!

(steep learning curve for an oldie like me!)

Question Author

Thank you fo3nix, this is something I'm going to look at.

Top marks both!

-- answer removed --

1 to 8 of 8rss feed

Related Questions