Still wonder how to automatic update copyright year instead of changing hard-coded value each year. Lol!! You need some fresh air to let your mind breathe. Use PHP’s date()
function which can echo the current year in your copyright text.
1 | Copyright ©<?php echo date('Y'); ?> | Your Company Name |
There are many variations of the same code above. if you are using a start year as well then:
1 2 3 4 5 6 7 8 9 10 11 | <?php function copyright_info($begin_year = NULL) { if(empty($begin_year) || $begin_year == date('Y')) echo date('Y'); else echo $begin_year." - ".date('Y'); } ?> Copyright ©<?php copyright_info('2010'); ?> | Your Company Name |
Or can use either like this while developing website initially
1 2 3 4 5 6 7 | <p>Copyright © <?php $current_year = date("o"); if ($current_year == "2015") echo "2015"; else echo "2015 - $current_year"; ?> <acronym title="Fellow Tuts">Fellow Tuts</acronym>. All rights reserved.</p> |
Choice is yours! Core is just use date('Y')
function to let PHP update year automatically in your copyright text.
As a note: Don’t use jQuery or JavaScript to automatic update copyright year because it’s prone to abuse or great error as you’d be relying on the end user’s PC to have the right time unless you were using AJAX to pull the real time from the server.
thanks