Monday, December 8, 2014

Change banner rotation each day

Problem:   
Our customer need to change the banner exposition to a different one each day, we only have 2 banner options soo, we only need to show a different banner each day.

 Solution:    

To do that, i think on read the day of current date, divide by 2 it and get the rest part of the division. If the rest part is nan then show banner A, else show banner B.

Steps:
' Reading current date
$date = date("ymd");

' Get current day number
$day_number = date('n', strtotime($date));

' divide it by 2
$res = substr($date, 4, 2) %2 ;

' final condition
if ($res==0){ 'show banner a }else{ 'show banner b }

No comments:

Post a Comment