Copy of php Script

It’s not always convenient to put the year of creation and the current year on websites.

For example: copyright 2003-2030

To avoid constantly changing the last year, there is a PHP solution.

<?php define(‘COPYRIGTH_YEAR_FROM’, ‘2009’); if(date(‘Y’) == COPYRIGTH_YEAR_FROM) { echo ‘&copy; ‘.COPYRIGTH_YEAR_FROM; } else { echo ‘&copy; ‘.COPYRIGTH_YEAR_FROM.‘-‘.date(‘Y’); } ?>


Script for the Copyright on PHP

If you intend to write a simple PHP script to automate the creation of copyright on your website, which will be automatically updated every year, you can use the following code:

<?php
$currentYear = date(“Y”); // Отримуємо поточний рік
$startYear = 2020; // Встановлюємо рік початку функціонування сайту

// Перевіряємо, чи поточний рік відрізняється від року старту
if ($currentYear > $startYear) {
echo “&copy; $startYear – $currentYear Ваша Компанія. Всі права захищені.”;
} else {
echo “&copy; $startYear Ваша Компанія. Всі права захищені.”;
}
?>

In this script, the variable `$startYear` is first set to contain the year when the website was launched. Using the `date(“Y”)` function, we get the current year, which is stored in the `$currentYear` variable. The next step is to check if the current year is greater than the year the website was launched, then the copyright text with the range of years is displayed. If they are the same, i.e. the website was launched in the current year, then the year of launch is displayed.

It is worth noting that according to PHP standards, it is recommended to use single quotes for strings if there are no variables or special characters to be processed inside them, as this slightly increases the speed of code processing. In addition, when adding HTML structure or additional elements, you should take into account the correct syntax and tagging.

Оцените статью
A7 Design Studio
Copy of php Script
Copy of php Script