Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

Changing page background in PHP according to time

images php coding issues or problems here.

Moderators: macek, egami, gesf

Changing page background in PHP according to time

Postby MegaSonicX » Wed Apr 14, 2010 4:05 pm

OK so I'm making a site and I want to use PHP to make the background change according to the time. I tried this code but it doesn't work:

index.php
Code: Select all
<?php
$hour = date('H');
if ($hour < 12 ) {
    echo '<link rel="stylesheet" type="text/css" href="style.css" />;
}
elseif ($hour < 12 ) {
    echo '<link rel="stylesheet" type="text/css" href="style2.css" />';
}
elseif ($hour < 17 ) {
    echo '<link rel="stylesheet" type="text/css" href="style3.css" />';
}
else {
   echo'You messed up man.';
}
?>


And this is the CSS

style.css
Code: Select all
body {
background-image:url('background.png');
}


They're both in a folder called time.png
Please help me!
MegaSonicX
New php-forum User
New php-forum User
 
Posts: 1
Joined: Wed Apr 14, 2010 12:35 pm

Re: Changing page background in PHP according to time

Postby Patfreeze » Tue Apr 20, 2010 10:12 am

Check my comment on the code
Code: Select all
<?php
$hour = date('H');
if ($hour < 12 ) { /***** if $hour is between 0 to 12 ****/
    echo '<link rel="stylesheet" type="text/css" href="style.css" />;
}
else if ($hour > 13 AND $hour < 17 ) { /***** if $hour is between 12 to 16 ****/
    echo '<link rel="stylesheet" type="text/css" href="style2.css" />';
}
else if ($hour < 18 ) { /***** if $hour is between 17 to 24 ****/
    echo '<link rel="stylesheet" type="text/css" href="style3.css" />';
}
else {
   echo 'You messed up man.'; /***** supose that $hour not defined ****/
}
?>

hope that will help you :D
User avatar
Patfreeze
New php-forum User
New php-forum User
 
Posts: 41
Joined: Tue Apr 20, 2010 9:51 am
Location: Canada - Quebec


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron