I want to put a copyright notice in the footer of a web site, but I think it's incredibly tacky for the year to be outdated. How would I make the year update automatically with PHP

 

To automatically update the copyright year in the footer of a website using PHP, you can use PHP's date function to get the current year dynamically. Here's an example of how to do it:

html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Your Website</title> </head> <body> <footer> <p>&copy; <?php echo date("Y"); ?> Your Company Name. All rights reserved.</p> </footer> </body> </html>

In this example:

  1. We embed PHP code within the HTML to execute date("Y"), which will return the current year when the page is loaded.

  2. The &copy; character entity is used to display the copyright symbol (©).

  3. We concatenate the current year obtained from date("Y") with the rest of your copyright notice, such as your company name and "All rights reserved."

When a visitor loads the webpage, PHP will dynamically replace <?php echo date("Y"); ?> with the current year, ensuring that the copyright notice always displays the current year.

As time progresses, the year will automatically update without you needing to manually edit the HTML each year, making it a convenient and dynamic solution for displaying the copyright year on your website.

Comments