Log in

View Full Version : show year in html page



AndyK
01-09-2008, 08:15 PM
I am new to PHP and have read tutorials and have created a .php called date.php with the coding:


<html>
<head>
<title>PHP Date Test</title>
</head>
<body>

Copyright &copy; 2003-<?php
echo date("Y");
?> Autograph Arcade. &nbsp;All rights reserved.


</body>
</html>

then if I type in the domain www.autographarcade.com/date.php it works and shows the sentence and the current year which is what I want.

My problem is, how do I now put this script in front of the words in the other html documents so it shows the current year and I do not have to change hundreds of pages manually every year?

Thanks AndyK

Wrapped the code in
tags

boogyman
01-09-2008, 08:43 PM
put

<?php
echo date("Y");
?>
in every file just like you have in this... or better yet... separate the footer file and include the footer on every page so if you ever change the footer all of the pages change instead of changing each page manually

AndyK
01-09-2008, 08:48 PM
Hello, I tried that but it doesn't work. That script has to be in a .php doesnt it? It doesn't work in a .html. There must be more to it.

boogyman
01-09-2008, 09:06 PM
yes pages must be in a form of php extension.

AndyK
01-09-2008, 09:19 PM
So are saying I need to change ALL the .html pages to .php? That can't be right that's WAY to much work all the links and everything would have to changed that would take months and I mean months. Plus the search engines has the pages in as html. That would take ages to pick them all up. Unless I am not understanding what you are saying? Isn't they any kind of other script I can just put in the html file that will change the date automatically?

thetestingsite
01-09-2008, 09:24 PM
You could probably use javascript, but that wouldn't be as effective because end users can disable javascript in their browsers.

Hope this helps.

boogyman
01-09-2008, 09:33 PM
So are saying I need to change ALL the .html pages to .php? That can't be right that's WAY to much work all the links and everything would have to changed that would take months and I mean months. Plus the search engines has the pages in as html. That would take ages to pick them all up. Unless I am not understanding what you are saying? Isn't they any kind of other script I can just put in the html file that will change the date automatically?

changing from html to php pages shouldn't take months. The only thing you would need to do is open each html file into some type of text editor and click "save as" and save it as "fileName.php" basically just adding the .php at the end. that would change the html files to the php files... including the footer is meerly just 1 more line, but while you are at it you could probably create a separate template for the generic headings too, and possibly the global nav bar if you have one... so your new page would look like



<?php include_once("/path/to/header"); ?>

__BODY__

<?php include_once("/path/to/footer"); ?>


and you would just copy and paste the generic header and create a new file for the header and 1 for the footer. then just hit save as and save it with the php extension...

if you are saying it would take MONTHS to do this, then it may be beneficial to start looking into a template / database driven website. but those are just my 2 cents...

as testingsite mentioned you could use javascript, however it is not 100% fool proof because users can disable javascript, in which case they would not see the year... in either event if if you needed to update the HTML files to include the new date processes anyway? how hard is it to create the template ?? PHP pages do not need to contain only php code... while its preferred that content and management remain separate, it is possible to have an entirely html page with a php extension.

AndyK
01-09-2008, 09:58 PM
Thanks again for your help.

The only thing I would be concerned about then is the search engines. I have all my pages in as .html as you know. The problem would be people could not use the links to get to the web page. They would be html files until the search engines pick them up and change they database and you know how long that can take. Plus its a business website and would cost me money. Therefore I think if I could find a javascript that does it, that might be better. Do you know a website that might have this script?

AndyK

thetestingsite
01-09-2008, 10:10 PM
Well, you may be able to set .html pages as php files by using htaccess. For more info, simply search for htaccess here in the forums and that should help you out.

Hope this helps.

AndyK
01-09-2008, 10:22 PM
Thanks for your help guys, I just found this JavaScript that does it.

<script type="text/javascript">
var d = new Date();
document.write(d.getFullYear());
</script>

I realize that people close there JavaScript, that's there choice. Thanks again everyone!

AndyK