Jump to content

[SOLVED] time based greeting all timezones


gwolff2005

Recommended Posts

Hi guys,

I need your help. I have a script which shows the time on my server, but does not realize the clients timezones. How can I greet my customers according to THEIR timezone?

 

print date("g:ia"); 

$date = date ("H"); 

if ($date < 6) { 
echo "Good Morning "; 
} elseif ($date < 7) { 
echo "Good Morning"; 
} elseif ($date < 12) { 
echo "Good Morning "; 
} elseif ($date < 18) { 
echo "Good Afternoon "; 
} elseif ($date < 22) { 
echo "Good Evening "; 
} elseif ($date < 24) { 
echo "Good Evening"; 
} 

?>

Link to comment
Share on other sites

ask them most common.

 

untested support at url .

 

http://stackoverflow.com/questions/13/determining-web-users-time-zone

function ajaxpage(){
    var url = "timezone.php";
var visitortime = new Date();
vat time = visitortime.getTimezoneOffset()/60;
   var page_request = false
if (window.XMLHttpRequest)
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ 
    try {
page_request = new ActiveXObject("Msxml2.XMLHTTP") } 
catch (e){
    try{
page_request = new ActiveXObject("Microsoft.XMLHTTP") }
catch (e){}}}
else
return false
page_request.onreadystatechange=function(){
    loadpage(page_request, containerid) }

if (bustcachevar)
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter+"&time="+time, true)
page_request.send(null) }


function loadpage(page_request, containerid){
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
    document.write('<meta http-equiv="refresh" content="0;url=http://example.com/"/>'); }

 

<?php
session_start();
$_SESSION['time'] = $_GET['time'];
?>

Link to comment
Share on other sites

you could use geoip to locate them and map that to a timezone however this is labour intensive.

 

if you have users that login perhaps ask them to select which timezone they reside in (save it in their profile) and use that to amend your base time ins any computations/display. you could also set a cookie for guest visitors - a discreet part of the page could request their timezone or a nasty javascript pop-up (even a nicely-still nasty for UI styled ajax pop-up).

Link to comment
Share on other sites

what if javascript is off? admittedly i doubt this is a critical task - but i am always of the ilk that your site should work - not be dependant on any technologies that may or may not be available.

 

in this case yeah I'll concede the js option is probably right.

Link to comment
Share on other sites

If you are expecting to personalize a site to your visitor's timezone, you should provide a way for the visitor to set his GMT offset/time zone (saved in your user table per visitor or even as a cookie that would get sent with each page request.) You can offer to autodetect it using some javascript, but that should not be the primary method.

Link to comment
Share on other sites

Hi, I integrated now the code exactly like this into my php document

 

<script type="text/javascript">/*<![CDATA[*/
	function clock()
	{
		//////////////////////////////////////////////////////
		//Coded by the notorious jackpf
		/////////////////////////////////////////////////////

		//generate time
		var time = new Date();
		var hours = time.getHours();
		var minutes = time.getMinutes();
		var seconds = time.getSeconds();

		//add preceding 0s, if required
		var hours = (hours < 10 ? '0' : '')+hours;
		var minutes = (minutes < 10 ? '0' : '')+minutes;
		var seconds = (seconds < 10 ? '0' : '')+seconds;

		//generate formated time
		var time = hours+':'+minutes+':'+seconds;

		//display time
		document.getElementById('clock').innerHTML = time;
	}
	//init clock
	window.onload = function()
	{
		clock();
		setInterval('clock()', 1000);
	}
/*]]>*/
</script>

 

and I entered

<span id="clock"></span>

what do I have to write now to make it visible for the users to see either good morning/afternoon/evening depending on THEIR time?

 

Thanks so much!

Link to comment
Share on other sites

Hey,

you rock! What did you do? What do I have to do, to get it done. So, when I have the time? whta do I have to write in java ( i don't know the language and in php I am a newbie) to show the visitors, good morning, good afternoon or good evening, depending on their time??? I really appreciate your help. I owe you something!

Link to comment
Share on other sites

<script type="text/javascript">
/*<![CDATA[*/
	function clock()
	{
		//////////////////////////////////////////////////////
		//Coded by the notorious jackpf
		/////////////////////////////////////////////////////

		//generate time
		var time = new Date();
		var hours = time.getHours();
		var minutes = time.getMinutes();
		var seconds = time.getSeconds();

		//add preceding 0s, if required
		var hours = (hours < 10 ? '0' : '')+hours;
		var minutes = (minutes < 10 ? '0' : '')+minutes;
		var seconds = (seconds < 10 ? '0' : '')+seconds;

		//generate formated time
		var time = hours+':'+minutes+':'+seconds;

		//get where abouts in the day it is
		if(hours >= 0 && hours < 12)
		{
			var greeting = 'Good morning';
		}
		else
		{
			var greeting = 'Good evening';
		}

		//display time
		document.getElementById('clock').innerHTML = time+'<br />'+greeting;
	}
	//init clock
	window.onload = function()
	{
		clock();
		setInterval('clock()', 1000);
	}
/*]]>*/
</script>
<span id="clock"></span>

 

Somethin glike that?

You can add more greetings in if you want, but that's the basics. And no problem.

Link to comment
Share on other sites

Hi Jackpf I got this message

Warning: Cannot modify header information - headers already sent by (output started at /home/guntmar/public_html/intro.php:35) in /home/guntmar/public_html/intro.php on line 77

 

This is the code right now

 

<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);

  $logoutGoTo = "http://www.guntmarwolff.com";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php require_once('Connections/Login.php'); ?><?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
?>
<span id="clock"></span>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
// For security, start by assuming the visitor is NOT authorized. 
$isValid = False; 

// When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
// Therefore, we know that a user is NOT logged in if that Session variable is blank. 
if (!empty($UserName)) { 
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
// Parse the strings into arrays. 
$arrUsers = Explode(",", $strUsers); 
$arrGroups = Explode(",", $strGroups); 
if (in_array($UserName, $arrUsers)) { 
$isValid = true; 
} 
// Or, you may restrict access to only certain users based on their username. 
if (in_array($UserGroup, $arrGroups)) { 
$isValid = true; 
} 
if (($strUsers == "") && true) { 
$isValid = true; 
} 
} 
return $isValid; 
}

$MM_restrictGoTo = "index.html";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo); 
exit;
}

?>

<!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>Intro</title>
<style type="text/css">
<!--
.style3 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
color: #000033;
}
.style8 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #000033; font-weight: bold; }
.style11 {color: #000033}
-->
</style>
</head>
<body>
<p> </p>
<table width="917" border="0">
  <tr>
    <td height="32" colspan="2" class="style8"><span class="style8">
<?php echo " " .  $_SESSION['MM_firstname']; ?></span></td>
    <td width="71" class="style8"> </td>
    <td width="107" class="style8"> </td>
    <td class="style3"> </td>
    <td width="164" class="style3"><div align="left"><span class="style3"><?php echo "You are logged in as<br>"?><em><strong><?php echo $_SESSION['MM_Username']; ?></strong></em></span></div></td>
    <td width="163" class="style3"><span class="style8"><a href="<?php echo $logoutAction ?>"><img src="pics/logout.jpg" width="86" height="24" border="0" longdesc="http://www.guntmarwolff.com" /></a></span></td>
  </tr>
  <tr>
    <td colspan="2" class="style3">script type="text/javascript">
/*<![CDATA[*/
	function clock()
	{
		//////////////////////////////////////////////////////
		//Coded by the notorious jackpf
		/////////////////////////////////////////////////////

		//generate time
		var time = new Date();
		var hours = time.getHours();
		var minutes = time.getMinutes();
		var seconds = time.getSeconds();

		//add preceding 0s, if required
		var hours = (hours < 10 ? '0' : '')+hours;
		var minutes = (minutes < 10 ? '0' : '')+minutes;
		var seconds = (seconds < 10 ? '0' : '')+seconds;

		//generate formated time
		var time = hours+':'+minutes+':'+seconds;

		//get where abouts in the day it is
		if(hours >= 0 && hours < 12)
		{
			var greeting = 'Good morning';
		}
		else
		{
			var greeting = 'Good evening';
		}

		//display time
		document.getElementById('clock').innerHTML = time+'<br />'+greeting;
	}
	//init clock
	window.onload = function()
	{
		clock();
		setInterval('clock()', 1000);
	}
/*]]>*/
</script>
<span id="clock"></span>
</td>
    <td colspan="2"> </td>
    <td width="125"> </td>
    <td valign="top"> </td>
    <td class="style3"><span class="style11">
      <?php 
//This file shows you how to include the file in your php document.


include("online.php"); 
?>
    </span></td>
  </tr>
  <tr>
    <td width="95"> </td>
    <td width="162"> </td>
    <td colspan="2"> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
    <td colspan="2" rowspan="15"> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
</table>
<p> </p>
<p> </p>
<p> <a href="<?php echo $logoutAction ?>"></a></p>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.