Results 1 to 10 of 10

Thread: show year in html page

  1. #1
    Join Date
    Jan 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default show year in html page

    I am new to PHP and have read tutorials and have created a .php called date.php with the coding:

    PHP Code:
    <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

    Edit: Wrapped the code in [php][/php] tags
    Last edited by tech_support; 01-10-2008 at 01:22 AM.

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    put
    Code:
    <?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

  3. #3
    Join Date
    Jan 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  4. #4
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    yes pages must be in a form of php extension.

  5. #5
    Join Date
    Jan 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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?

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You could probably use javascript, but that wouldn't be as effective because end users can disable javascript in their browsers.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by AndyK View Post
    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

    Code:
    <?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.

  8. #8
    Join Date
    Jan 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  9. #9
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    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.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  10. #10
    Join Date
    Jan 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •