...

View Full Version : display a image for afternoon, morning, night



muggzy
12-31-2005, 04:13 PM
Hi there,

here's a easy one i hope, i want to display a image for good morning, good afternoon and good evening based on the time. cant find a script that does this as they all just deal with echoing text rather than a image. if anyone knows of a script for this could you help me out? thanks!

degsy
12-31-2005, 05:25 PM
they all just deal with echoing text rather than a image
Just replace the text with the image code.

Edit: posted wrong code

muggzy
12-31-2005, 05:33 PM
thanks degsy your a absolute star, just a quick question, after i make my separate php page with the code you gave me, whats the line of code to insert it into the html?

thanks mate

degsy
12-31-2005, 05:54 PM
The full php file could be



<?php
$time = date("H:i:s");

if($time > '00:00:00' && $time < '12:00:00'){
$msg = 'Good morning';
$img = 'http://www.google.co.uk/intl/en_uk/images/logo.gif';
}
elseif($time > '12:00:00' && $time < '18:00:00'){
$msg = 'Good afternoon';
$img = 'http://search.msn.co.uk/s/hp/bluesky_logo.gif';
}
else{
$msg = 'Good evening';
$img = 'http://us.a1.yimg.com/us.yimg.com/i/us/search/b/syc_logo_2.gif';
}

?>
<img src="<?php echo $img; ?>" alt="<?php echo $msg; ?>" />


or you could make it into a function and call it.

degsy
12-31-2005, 05:59 PM
<?php
function greeting(){

$time = date("H:i:s");

if($time > '00:00:00' && $time < '12:00:00'){
$msg = 'Good morning';
$img = 'http://www.google.co.uk/intl/en_uk/images/logo.gif';
}
elseif($time > '12:00:00' && $time < '18:00:00'){
$msg = 'Good afternoon';
$img = 'http://search.msn.co.uk/s/hp/bluesky_logo.gif';
}
else{
$msg = 'Good evening';
$img = 'http://us.a1.yimg.com/us.yimg.com/i/us/search/b/syc_logo_2.gif';
}

$greeting = "$time - $msg <br><img src=\"$img\" alt=\"$msg\" />";

return $greeting;
}
echo greeting();
?>

muggzy
12-31-2005, 06:31 PM
ok ive made a seperate file called time.php with this code


<?php
function greeting(){

$time = date("H:i:s");

if($time > '00:00:00' && $time < '12:00:00'){
$msg = 'Good morning';
$img = 'http://www.google.co.uk/intl/en_uk/images/logo.gif';
}
elseif($time > '12:00:00' && $time < '18:00:00'){
$msg = 'Good afternoon';
$img = 'http://search.msn.co.uk/s/hp/bluesky_logo.gif';
}
else{
$msg = 'Good evening';
$img = 'http://us.a1.yimg.com/us.yimg.com/i/us/search/b/syc_logo_2.gif';
}

$greeting = "$time - $msg <br><img src=\"$img\" alt=\"$msg\" />";

return $greeting;
}
echo greeting();
?>

now in my index.html, what do i put to make that line of code work, is it <img src="<?php echo $img; ?>" alt="<?php echo $msg; ?>" />

i dont think ive got that right

degsy
12-31-2005, 06:34 PM
create a file called greeting.php



<?php
$time = date("H:i:s");

if($time > '00:00:00' && $time < '12:00:00'){
$msg = 'Good morning';
$img = 'http://www.google.co.uk/intl/en_uk/images/logo.gif';
}
elseif($time > '12:00:00' && $time < '18:00:00'){
$msg = 'Good afternoon';
$img = 'http://search.msn.co.uk/s/hp/bluesky_logo.gif';
}
else{
$msg = 'Good evening';
$img = 'http://us.a1.yimg.com/us.yimg.com/i/us/search/b/syc_logo_2.gif';
}

?>
<img src="<?php echo $img; ?>" alt="<?php echo $msg; ?>" />


You will have to change your index file to php.

index.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
whatever other code you want

<?php
// put the include code where you want the image to appear
include 'greeting.php';
?>

</body>
</html>

muggzy
12-31-2005, 08:14 PM
thanks! that worked great, Just wondering, is the time based on the users computer or the servers? its 19.00 in the uk and its saying good afternoon :(

degsy
12-31-2005, 08:24 PM
PHP scripts are server side and so take the Servers time.
You can alter the time accordingly.
http://uk2.php.net/manual/en/function.date.php
http://uk2.php.net/gmdate


To use the users time you would have to use javascript or submit grab locational information from their browser.

muggzy
12-31-2005, 09:11 PM
ok ive got a idea, is it possible to find out the time on my server? cos if it is then, i can adjust the times in the scripts by how many hours ahead/behind it is in the uk!!

er does that sound right?

Kurashu
12-31-2005, 09:30 PM
echo date('H:i:s');

That'll help.

degsy
01-01-2006, 05:33 PM
ok ive got a idea, is it possible to find out the time on my server? cos if it is then, i can adjust the times in the scripts by how many hours ahead/behind it is in the uk!!

er does that sound right?



PHP scripts are server side and so take the Servers time.
You can alter the time accordingly.
http://uk2.php.net/manual/en/function.date.php
http://uk2.php.net/gmdate




<?
$time = date('H:i:s', strtotime('-5 hours'));
echo $time;
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum