Monday, July 17, 2017

learn how to create an automatic copyright year and automatic background

How to create dynamic background and automatic copyright  year  with php

In this article you will learn how to create dynamic background and automatic copyright year  using a very simple php codes. This tutorial will show you the power of php language. 



 Creating a background that charges everyday with php 

The scope of this stage is using the php date documentation to manipulate the html background image tag. Follow the steps below to accomplish this 
 Firstly you will prepare seven different images you want to use for your background for the seven different days and name it in this format background_1.png, background_2.png till background_7.png not you can use any name you like but make sure to include the [yourbackroundname_no.imageformat ]. 


You can use transparent solid color images.,it left to you but make sure you optimize your images before uploading it to learn how to optimize images read this article 
After Saving the images in your desire path on your sever directory .
Edit your source code and add this code to your body elements 
< body background=”background_<? php echo date('w'); ?>.png >
 Note that we use background_<? php>.png because we save our images as background_1.png and if your images are not under your root directory you should specify the complete url to it.

create automatic copyright year with php.

Php is the best choice when it comes to using the date documentation because the date are fro the sever date not the client own. You should know that this javascript code will also create an automatic copyright year 
Copyright 2014- <script type="text/javascript">
var d = new Date();
document.write(d.getFullYear());
</script>


But the downside about it is that is your user date is not correct it's going to display the incorrect Date as your copyright date.
This is where php come handy.
&copy;<?php echo date('Y');  ?>
Or copyright 2014-<?php echo date('Y');  ?>
A more dynamic code and result use php function to manipulate 
<?php function auto_copyright($year = 'auto'){ ?>
   <?php if(intval($year) == 'auto'){ $year = date('Y'); } ?>
   <?php if(intval($year) == date('Y')){ echo intval($year); } ?>
   <?php if(intval($year) < date('Y')){ echo intval($year) . ' - ' . date('Y'); } ?>
   <?php if(intval($year) > date('Y')){ echo date('Y'); } ?>
<?php } ?>
Calling the function 
&copy;<?php auto_copyright("2014");   ?>
Or 
Copyright <?php auto_copyright("2014");   ?>
Choose any of the code you preferred and edit you source code and input it into your footer appropriately.

If you get it right don't forget to drop your comments below if you also have any questions drop you comments below and share .

No comments:

Post a Comment