Warning: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in ..../includes/class_bbcode.php on line 2083
Simple Auto-Update Copyright Script
Results 1 to 9 of 9

Thread: Simple Auto-Update Copyright Script

  1. #1
    Sean
    Join Date
    Nov 2005
    Posts
    139

    Simple Auto-Update Copyright Script

    This is a very simple php script I put together so I wouldn't have to update my copyright statements on all my sites (which I hope to eventually have lots of) each year. I know that it's very simple but, since it does no harm to share it, I figured maybe someone who doesn't know PHP or someone who does and didn't think of it could find it handy.

    HTML Code:
    ITEM Copyright ©
    
    <?php 
    
    if (date("Y") == '2005')
    {
    echo date("Y");
    }
    else
    {
    echo '2005-'; echo date("Y"); 
    }
    
    ?> 
    
    NAME. All Rights Reserved.
    If the current year is 2005, it will display:

    "ITEM Copyright © 2005 NAME. All Rights Reserved."

    If the current year is over 2005, it will display:

    "ITEM Copyright © 2005-XXXX NAME. All Rights Reserved."

    Where XXXX is the current year.

    Just replace "NAME" with your company or site's name and "ITEM" with whatever it is you're stating your copyright for (i.e "site", "layout" or "content") and you shouldn't have to touch it. Also, you can replace the captal Y in the third "date("Y")" with a lower-case "y" to display just the last 2 digits of the current year ("2005-06")... but I prefer the full year.

    If you're seeing/using this in 2006+ just replace both 2005's in the PHP with your current year.

    Again I know it's really simple but could save some time and effort over the years if you have a lot of sites.

    EDIT:

    here's a link to the date() function incase anyone has any other ideas for it:

    http://php.net/manual/en/function.date.php
    Last edited by Sean; 11-07-2005 at 04:58 AM.

  2. #2
    Registered LuckyShima's Avatar
    Join Date
    Jan 2004
    Posts
    207
    Your second '2005' really should be a variable so you don't have to change it in two places.

    So ... $setup_year = '2005' ... if (date("Y") == $setup_year) .... echo $setup_year

    And there is another way of doing it:

    $setup_year = "2000";
    $current_year = date("Y");

    echo $setup_year;

    if ($current_year != $setup_year) {
    echo " - $current_year";
    }
    Last edited by LuckyShima; 11-07-2005 at 12:08 PM.

  3. #3
    here's the way I would do it. A lot shorter, and in the end when you have lots of pages that can be viewed, also quicker.
    PHP Code:
    <?
        $setup_year 
    "2000";
        
    $current_year date("Y");
        echo 
    $setup_year.($current_year != $setup_year " - $current_yearnull);
    ?>
    Roger Stringer - freekrai.net
    DBStract - Build Virtual Databases

  4. #4
    Sean
    Join Date
    Nov 2005
    Posts
    139
    Yeah you guys are right. I'll have to update my pages.

    I'm still pretty new to PHP so don't really know all the optimization, more focused on just getting the scripts to work heh. I should learn to optimize though incase a site I have gets big... it wont eat up all my resources and slow down my pages.

    Thanks for fixing it.
    Last edited by Sean; 11-07-2005 at 01:55 PM.

  5. #5
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    ..there is more than one way to skin a cat.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  6. #6
    Chronic Entrepreneur
    Join Date
    Nov 2003
    Location
    Tulsa, Oklahoma, USA
    Posts
    1,112
    Quote Originally Posted by Chris
    ..there is more than one way to skin a cat.
    A more efficient way to say that would have been, "There's more than one way to skin a cat."

  7. #7
    I'm the oogie boogie man! James's Avatar
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    1,566
    And a gramatically incorrect way would be
    "There are more than one way to skin a cats."

  8. #8
    Registered tommy_sir's Avatar
    Join Date
    Oct 2005
    Posts
    20

    well

    can any ASP CODE?
    http://www.py168.com
    http://www.cncolor.net
    i am a chinaese webmaster, can you be my friends?

  9. #9
    I'm the oogie boogie man! James's Avatar
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    1,566
    Code:
    CurrDate = Now()
    CurrYearID = Month(CurrDate)
    response.write "Copyright " & CurrYearID
    Try that. I've just pieced it together based on what a quick Google search and scanning turned up, so it may not work.

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
  •