PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old October 17th, 2009, 06:52 PM
jonloovox jonloovox is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 3 jonloovox User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 40 sec
Reputation Power: 0
images - Time-based image rotation script

Hi PHP community!

I'm trying to write a PHP script that rotates an image based on what time of day it is. I want the script to show day.jpg from 6 AM to 6 PM, and to show night.jpg from 6 PM to 6 AM.

I also need the rotation to take place based not on server time, but on the local time of the user viewing the page.

I've Google-searched this for hours and only found stuff that is similar but doesn't do what I want. I don't want the rotation to be "every X minutes" and I don't want it to be based on the date, but rather on the exact time of day based on a user's local time.

Thank you SO much. This is very important to me.

Best,

Robert

Reply With Quote
  #2  
Old October 17th, 2009, 07:00 PM
MatthewJ MatthewJ is offline
Contributing User
Click here for more information.
 
Join Date: May 2007
Location: Davenport, Iowa
Posts: 564 MatthewJ User rank is Private First Class (20 - 50 Reputation Level)MatthewJ User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 21 h 23 m 45 sec
Reputation Power: 3
You could do this with javascript

Get Users time zone/current time

Once you get their timezone and figure out what time it is there, it should be pretty simple to tell the page which image to show.

Reply With Quote
  #3  
Old October 17th, 2009, 08:12 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
matthew is right, the only real way to get the clients date/time is through javascript. you could load the background image through javascript and apply it to the body or do something like save the date/time through javascript to a cookie and on the next page load php could read the cookie and do whatever change you need.

Reply With Quote
  #4  
Old October 17th, 2009, 09:19 PM
jonloovox jonloovox is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 3 jonloovox User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 40 sec
Reputation Power: 0
Okay, I'm a super newb at this. I have no idea how to write the PHP code even once I have the Javascript code in the link Matt sent. I'm so sorry, but can you help a little more?

Reply With Quote
  #5  
Old October 19th, 2009, 03:02 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
here is a fully working example using nothing but javascript. it checks the hour in the current day based on the users time and then changes the background image from a default image (default is shown if javascript is turned off) to whatever image you want, just change the image url in the function.
Code:
<html>
<head>
<style type='text/css'>
body { background-image: url(default.jpg); background-repeat: no-repeat; background-position: top center; }
div { width: 600px; height: 70%; overflow-y: auto; margin: 100px auto; background-color: white; border: 2px solid black; }
</style>
<script type='text/javascript'>
function changeBG(){
    date = new Date;
    if(date.getHours() < 6 || date.getHours() >= 18){
        //night time.
        document.body.background = "moon.jpg";
        document.body.style.backgroundColor = "#000044";
    } else {
        //day time.
        document.body.style.backgroundColor = "#000044";
        document.body.background = "sun.jpg";
    }
};
</script>
</head>
<body onload="javascript:changeBG();">
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat justo in magna iaculis 
id pretium massa tristique. Vestibulum eu nisi eros, id hendrerit diam. Suspendisse luctus leo sit 
amet velit porta sed egestas metus condimentum. Aenean convallis nisi vitae metus pretium rhoncus. 
Nam tempor neque quis felis vulputate ornare. Suspendisse potenti. Vestibulum ante ipsum primis in 
faucibus orci luctus et ultrices posuere cubilia Curae; Sed viverra, mi ac rhoncus convallis, tortor 
velit vulputate felis, vitae porta nulla ipsum a nibh. Sed mollis, erat ac mattis fringilla, ante 
tortor pharetra leo, sit amet rutrum odio metus et elit. Mauris lacinia commodo libero eget ultricies. 
Nam ligula sem, hendrerit sit amet vehicula eget, posuere a neque. Proin metus risus, viverra a 
volutpat in, luctus ut nibh. Fusce blandit mi nec turpis ultrices ultricies. Cras posuere sapien 
a nibh vehicula sit amet iaculis dui ullamcorper. Sed non erat sapien, ac laoreet nunc. Sed non 
sem non sem placerat lobortis. Pellentesque euismod, nulla id gravida ullamcorper, urna diam pulvinar 
diam, sed eleifend lectus metus non tellus.</p>

<p>Ut id vulputate arcu. Curabitur non augue ipsum, eget iaculis metus. Class aptent taciti sociosqu 
ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur ornare accumsan justo, non 
bibendum dolor pretium non. Nam et nisl nulla. Duis cursus lacus eros, sed imperdiet felis. Integer 
sed libero sapien. Suspendisse cursus lacinia tortor, ut malesuada dui pulvinar a. Aliquam gravida 
suscipit felis, sit amet consectetur arcu facilisis at. Morbi et mi sed velit tristique gravida. Nam 
sit amet leo ut augue molestie porta eget sit amet nisi. Suspendisse egestas dolor ornare nunc 
hendrerit vitae venenatis justo facilisis. Sed elit dolor, molestie et rhoncus in, semper ut orci. 
Nulla laoreet tempor nisi, non elementum mi aliquam vitae. Nullam ut ante nec sem eleifend vulputate 
in quis enim. Pellentesque vel diam nec metus euismod eleifend quis ac mauris. Praesent facilisis quam 
sit amet mi dignissim luctus.</p>

<p>Duis tempor blandit pellentesque. Vivamus felis risus, mattis quis condimentum vel, laoreet vel nibh. 
Nunc lobortis, neque vitae egestas posuere, nibh lorem mattis purus, non tincidunt urna lacus in mauris. 
Curabitur tellus tortor, laoreet non tincidunt non, aliquet eu nibh. Nulla tempor congue magna a lobortis. 
Ut tincidunt, enim sollicitudin dapibus mollis, risus lacus pulvinar arcu, eget ullamcorper orci ante sed 
odio. Integer vulputate, purus vel malesuada sodales, odio augue dapibus urna, ut placerat erat risus et 
purus. Fusce orci mi, viverra sed dapibus quis, faucibus eget est. Mauris a consequat nisl. Donec at lacus 
lacus, volutpat ornare mauris. Nunc varius lacus eget augue vestibulum id pulvinar ipsum placerat. Aenean 
est lacus, vulputate at egestas nec, rutrum eu orci. Sed eros orci, porta feugiat posuere vitae, porttitor 
sed sem. Sed varius venenatis orci, sed tempus est tempor at. Duis arcu metus, scelerisque ac ornare quis, 
condimentum non ipsum. Mauris dolor purus, varius faucibus mattis ac, dictum et nisi. Etiam euismod aliquet 
magna et condimentum. Curabitur eget urna enim.</p>

<p>Duis nulla nibh, aliquet sit amet euismod nec, vulputate et risus. Cum sociis natoque penatibus et 
magnis dis parturient montes, nascetur ridiculus mus. Sed et velit at ipsum eleifend tempor. Ut id 
sapien ante, non molestie ipsum. Nulla a ultricies enim. Morbi odio ipsum, faucibus a faucibus vitae, 
condimentum et mauris. Nullam a odio turpis, vitae viverra nulla. Quisque feugiat sem vitae lacus 
feugiat bibendum. Etiam at metus vel nunc interdum lobortis eu nec purus. Pellentesque a viverra purus.</p>

<p>Quisque sagittis nibh vel dolor rhoncus dapibus. Cras blandit rutrum lectus in volutpat. Maecenas 
malesuada nulla ut tellus ullamcorper imperdiet. Nullam at dui elit. Morbi scelerisque mi eu quam molestie 
sit amet semper sem lacinia. Nam aliquet volutpat sapien, placerat venenatis leo adipiscing sit amet. 
Maecenas volutpat nunc vel diam malesuada eget eleifend ligula blandit. Cras sit amet lacus vitae ligula 
condimentum fermentum a sit amet enim. Sed congue pulvinar ligula. Sed accumsan facilisis nisl, a 
vestibulum enim feugiat ut.</p>
</div>
</body>
</html>
Comments on this post
MatthewJ agrees: Not sure why I was thinking you would need time xzone first since client side is going to give their
time with the simple call to the date object. That's why we pay you the big bucks Llama

Reply With Quote
  #6  
Old October 19th, 2009, 05:51 PM
jonloovox jonloovox is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 3 jonloovox User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 40 sec
Reputation Power: 0
Wow, I appreciate you helping me with this. That was incredibly helpful and very conducive to what I'm trying to do.

Thank you and I wish you the best.

Robert

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > images - Time-based image rotation script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek