Local Time

Support, Snippets & Projects

Moderators: Moderator, Global Moderator

Post Reply
us3rX
Hero Member
Hero Member
Posts: 1194
Joined: Wed May 05, 2004 11:11 pm

Local Time

Post by us3rX »

Code: Select all

$f = "
<html><head><script type='text/javascript'>
var d = new Date()
document.write(d.getHours())
</script></head></html>
";
$h = $f;

if ($h > 6 and $h < 18)
{
	$theme_dir = "new-images/nav-light";
}
else
{
	$theme_dir = "new-images/nav-dark";
}
any one know why that wont work? if i change it to make it echo instead of setting it to $f it will work....

us3rX /ph34r.gif' class='bbc_emoticon' alt=':ph34r:' />
[align=center]

Image

"Time is never wasted, when your wasted all the time" ~ Radio Dj/Unknown Source

"Death is the inevitable end to the suffering of the living." ~Unknown

"You were born an original. Don't die a copy" ~Murdoc Niccals

[/align]
Scott
Administrator
Administrator
Posts: 1651
Joined: Sun Apr 25, 2004 6:08 am

Local Time

Post by Scott »

That quite simply, won't work. /blush.gif' class='bbc_emoticon' alt='(blush)' />

This does:

cookie.js:

Code: Select all

function setCookie(name,value)
{
var exdate=new Date()
exdate.setTime(exdate.getTime()+(3600*1000))
document.cookie=name+ "=" +escape(value)+ "; expires="+exdate
}

function getCookie(name)
{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1)
	{
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	}
	else
	{
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
	{
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}
index.php (or whatever):

Code: Select all

<html>
<head>
<script src="cookie.js" type="text/javascript"></script>
<script>
var c = getCookie('h')
var d = new Date()
var h = d.getHours()
setCookie("h", h)
if (c == null) {
	window.location.href="test.php"
}
</script>
</head>
<body>
<?php
echo $_COOKIE['h'];
?>
</body>
</html>
I think you'll be fine from now on in /smile.gif' class='bbc_emoticon' alt=':)' />
Last edited by Scott on Mon Nov 14, 2005 4:28 am, edited 1 time in total.
us3rX
Hero Member
Hero Member
Posts: 1194
Joined: Wed May 05, 2004 11:11 pm

Local Time

Post by us3rX »

thank you, again scott /biggrin.gif' class='bbc_emoticon' alt=':D' />

us3rX /ph34r.gif' class='bbc_emoticon' alt=':ph34r:' />
[align=center]

Image

"Time is never wasted, when your wasted all the time" ~ Radio Dj/Unknown Source

"Death is the inevitable end to the suffering of the living." ~Unknown

"You were born an original. Don't die a copy" ~Murdoc Niccals

[/align]
Post Reply

Return to “PHP &amp; MySQL”