[SOVLED] Newbie question involing integers.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pukka
Forum Newbie
Posts: 5
Joined: Sun Nov 30, 2003 5:23 am

[SOVLED] Newbie question involing integers.

Post 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?
ghost007
Forum Commoner
Posts: 49
Joined: Sat Nov 22, 2003 10:10 am

Why using Javascript?

Post 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
pukka
Forum Newbie
Posts: 5
Joined: Sun Nov 30, 2003 5:23 am

Post 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.
pukka
Forum Newbie
Posts: 5
Joined: Sun Nov 30, 2003 5:23 am

Post 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.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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
pukka
Forum Newbie
Posts: 5
Joined: Sun Nov 30, 2003 5:23 am

Post by pukka »

Thats perfect! Thank you soooo much! :)

Here, have some waffles for your hard work:
Image
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

lol no prob. good luck with your site.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post 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!
pukka
Forum Newbie
Posts: 5
Joined: Sun Nov 30, 2003 5:23 am

Post 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!
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
Last edited by McGruff on Sun Nov 30, 2003 7:15 pm, edited 1 time in total.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

:oops: :oops:
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

lol
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

LOL @ McGruff...

Now that is what I consider abuse of powers!
Post Reply