Welcome to WebmasterWorld Guest from 50.19.0.90

Forum Moderators: open

Message Too Old, No Replies

Help with a random numbers generator script.

     
4:32 pm on Apr 7, 2011 (gmt 0)

New User

joined:Mar 31, 2011
posts:7
votes: 0


Created the thread here from users recommandation, hopefully someone can help

[webmasterworld.com...]


Hello

I've got a php script that generates random number every page refresh as it's shown below


<?php
srand ((double) microtime( )*1000000);
$random_number = rand(1000,5000);
echo "$random_number";
?>


Everything is good but i would like an option over the script that will change the random generated number each x seconds, a value where i can choose on how many seconds another random number will be generated and shown


would appreciate the help
4:52 pm on Apr 7, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts:4965
votes: 10


Would something like this work?

<?php
srand ((double) microtime( )*1000000);
$random_number = rand(1000,5000);
echo "$random_number";
?>
<script>
setTimeout(function () {
window.location.reload();
}, 10000); // reload after 10 seconds
</script>

Or do you need to get this via AJAX?
3:20 pm on Apr 9, 2011 (gmt 0)

Junior Member

10+ Year Member

joined:June 17, 2003
posts: 159
votes: 0


If you did the coding in JavaScript instead of PHP, you could avoid both the reload and AJAX.
3:50 pm on Apr 9, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 20, 2004
posts: 703
votes: 0


I am wondering what a random number with every page refresh could be used for?
2:59 pm on Apr 26, 2011 (gmt 0)

New User

joined:Mar 31, 2011
posts:7
votes: 0


Hello sorry for my late response

Thanks for your help Fotiman

Unfortunately, the random number changes each page refresh. I don't want to do that.

Even if i would refresh the page, that number should change after a certain time i set,like in your scrit 10 seconds for example. But your script refreshes it after 10 seconds automatically. But if i refresh the page manually it will show a different number every time i do that.

Hope you can help me
4:30 pm on Apr 26, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts:4965
votes: 10


It sounds, then, that what you really need is some sort of cron job running on the server that will generate the value and persist it to a database or file which can then be read by your PHP script. It doesn't sound like a JavaScript issue, though, so you might try a forum that focuses on server side.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members