Local Time

Support, Snippets & Projects

Moderators: Moderator, Global Moderator

Post Reply
us3rX
Newbie
Newbie
Posts: 0
Joined: Thu May 06, 2004 6:11 am

Local Time

Post by us3rX »

Code: Select all

$f = "
<html><head><script type=\'text/j&#097;v&#097;script\'>
var d = new Date&#40;&#41;
document.write&#40;d.getHours&#40;&#41;&#41;
</script></head></html>
";
$h = $f;

if &#40;$h > 6 and $h < 18&#41;
{
	$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 <img src=\'http://www.killanet.net/forum3/public/s ... /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: 0
Joined: Sun Apr 25, 2004 1:08 pm

Local Time

Post by Scott »

That quite simply, won\'t work. <img src=\'http://www.killanet.net/forum3/public/s ... /blush.gif\' class=\'bbc_emoticon\' alt=\'(blush)\' />

This does:

cookie.js:

Code: Select all

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

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

Code: Select all

<html>
<head>
<script src="cookie.js" type="text/j&#097;v&#097;script"></script>
<script>
var c = getCookie&#40;\'h\'&#41;
var d = new Date&#40;&#41;
var h = d.getHours&#40;&#41;
setCookie&#40;"h", h&#41;
if &#40;c == null&#41; {
	window.location.href="test.php"
}
</script>
</head>
<body>
<?php
echo $_COOKIE&#91;\'h\'&#93;;
?>
</body>
</html>
I think you\'ll be fine from now on in <img src=\'http://www.killanet.net/forum3/public/s ... /smile.gif\' class=\'bbc_emoticon\' alt=\':)\' />
Last edited by Scott on Mon Nov 14, 2005 12:28 pm, edited 1 time in total.
us3rX
Newbie
Newbie
Posts: 0
Joined: Thu May 06, 2004 6:11 am

Local Time

Post by us3rX »

thank you, again scott <img src=\'http://www.killanet.net/forum3/public/s ... iggrin.gif\' class=\'bbc_emoticon\' alt=\':D\' />

us3rX <img src=\'http://www.killanet.net/forum3/public/s ... /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”