Page 1 of 1

[SOVLED] Newbie question involing integers.

Posted: Sun Nov 30, 2003 5:23 am
by pukka
I tried searching the forum, but came up with nothing.

Ok, basically, i have this code that takes the time in javascript and makes it a php variable. i have that all working, now what i want to do is be able to use that time variable and manipulate it like a regular integer variable.


here is the code:

Code: Select all

<?php 
$time = "<script language='javascript'>
d = new Date();
hr= d.getHours();
document.writeln(hr);
</script>"; ?>
this is your time<br>
<?php echo $time; ?>

<?php 
$time2 = intval($time );

$hour = $time3 * 2;
?>

<br>this is the hour<br>
<?php echo $hour; ?>
Doing an intval() doesn't work for some reason. Maybe its because the variably actually consists of javascript code. Anyway, si there anyway to make a new variable with only what the java script writes out instead of the whole script?

Why using Javascript?

Posted: Sun Nov 30, 2003 6:29 am
by ghost007
you can get the time in PHP which should solve all your time probs:

e.g.:

Code: Select all

<?php
$datetime = date ("F d Y H:i:s.");
echo $datetime;

?>
more info about the date function in php can be found here:
http://www.php.net/manual/en/function.date.php

hope this helps
siech

Posted: Sun Nov 30, 2003 6:36 am
by pukka
No, that gives you the time of the server, the key thing here is that we need the time of the user's PC.

Posted: Sun Nov 30, 2003 7:15 am
by pukka
Ok, now i understand thatit can't be done because php is a server side script. and java script is parsed ni the browser.
However, is there any way to do this using redirects? That would still be very useful.

any help would be greatly appreciated.

Posted: Sun Nov 30, 2003 8:40 am
by d3ad1ysp0rk
not sure about the syntax, but

Code: Select all

<script language='javascript'> 
d = new Date(); 
hr= d.getHours(); 
window.location = page.php?newdate=(hr);
</script>
and then on yourpage.php do whatever you want with the variable "newdate" or whatever you call it

Posted: Sun Nov 30, 2003 9:19 am
by pukka
Thats perfect! Thank you soooo much! :)

Here, have some waffles for your hard work:
Image

Posted: Sun Nov 30, 2003 11:06 am
by d3ad1ysp0rk
lol no prob. good luck with your site.

Posted: Sun Nov 30, 2003 11:18 am
by BDKR
pukka wrote:Thats perfect! Thank you soooo much! :)

Here, have some waffles for your hard work:
Image
LOL!

That is the coolest response I've EVER seen!

Posted: Sun Nov 30, 2003 11:42 am
by pukka
heh, thanks!

Anyway, if any of you are interested, here is the script

http://pukka.moonstarmedia.com/index.php

i split the day up into 6 parts, so if its noon, you'll be in part 4, and if its midnight, you'll be in part 1. the others fall inbetween. Try changing you clock around on your computer.

once again, thanks!

Posted: Sun Nov 30, 2003 7:06 pm
by McGruff
I'm afraid I abused my admin privileges to sneak a bite out of one of those waffles before they were picked up.

Image

Sorry couldn't resist.

Posted: Sun Nov 30, 2003 7:14 pm
by d3ad1ysp0rk
those were mine!!! :(

i was saving them for my first day back to school tommorow.. i needed the good start to the day.. now it's all gonna suck :(

lol

Posted: Sun Nov 30, 2003 7:16 pm
by McGruff
:oops: :oops:

Posted: Sun Nov 30, 2003 10:15 pm
by m3mn0n
lol

Posted: Sun Nov 30, 2003 10:25 pm
by JAM
LOL @ McGruff...

Now that is what I consider abuse of powers!