PDA

View Full Version : Need Help, it's very simple


Strack
08-21-2005, 08:30 AM
Hi there,
is anyone of you able to write a simple html-code wich only shows a code of 6 letters or numbers ? And they have to randomize every two hours ? Not only randomize, there has to be a completely new code? Probably like this: 13.55 there is a8jok3, 15.55 there is e04lps and so on. 7 days a week, 24 hours a day...

Thanks a lot if anyone does this for me, it's very important

coothead
08-21-2005, 12:56 PM
Hi there Strack,

and a warm welcome to these forums. :)
Is anyone able to write a simple html-code wich only shows a code of 6 letters or numbers ?
Unfortunately, this cannot be done with html. :supereek:

Here, though, is a javascript solution that may interest you...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>random selection</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>

<style type="text/css">
<!--
body {
background-color:#eef;
}
#ran_sel {
font-family:verdana,arial,helvetica,sans-serif;
font-size:18px;
color:#336;
text-align:center;
letter-spacing:5px;
width:180px;
line-height:50px;
border:3px double #669;
background-color:#fff;
margin:30px auto;
}
-->
</style>

<script type="text/javascript">
<!--
var selection=new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r',
's','t','u','v','w','x','z','0','1','2','3','4','5','6','7','8','9');
var subset=new Array(6);
var time=3000; // this is 3 seconds, 2 hours would be..... 1000*60*60
var test=0;

function getSix() {
if(test==1) {
document.getElementById('ran_sel').removeChild(output);
}
for(i=0;i<subset.length;i++) {
subset[i]=selection[Math.floor(Math.random()*selection.length)];
}
output=document.createTextNode(subset)
document.getElementById('ran_sel').appendChild(output);
test=1;
setTimeout('getSix()',time);
}
onload=getSix;
//-->
</script>

</head>
<body>

<div id="ran_sel"></div>

</body>
</html>

Strack
08-21-2005, 02:00 PM
thanks a lot, coothead.

but is it possible that all codes from one day will be shown up anywhere? thus I can see at 20.30 pm the code from 9.00 am? it's very important.
oh... and I just saw that the code changes if I restart the page. thats not good.

You probably have to know this: the code is for a gamepage from me. the page is about a game called Icy Tower, and it has become very popular worldwide.

But now, I want to make a league for the german players. the records of the game can be watched as replays. and I want to have one game being 2 hours. the problem of the game is that you can change the date of the replay and then someone could play now and sent them to me tomorrow.

but something in the replay can't be changed: its the name of the player. when the code is now there and they write it with their name, I can be sure that they just played at the time they should.

now you hopefully understand that the code shouldn't change by restarting. someone at an other pc must see the same code as I see it.

It would be very nice if you could help me.

coothead
08-21-2005, 02:26 PM
Hi there Strack,

what you are asking, cannot be achieved client-side. :supereek:
You will need to seek a solution server-side. :)

Ask a moderator to have this thread moved to the Server Side Programming (http://www.htmlforums.com/forumdisplay.php?f=19) forum.

Doug.Mellon
08-21-2005, 02:40 PM
You would prob. want to look into some PHP for this.
http://www.w3schools.com/php/default.asp
Adios,
Doug

scoutt
08-22-2005, 08:23 PM
to generate a random string jsut use this code,


<?php
session_start();
$twohours = 60*60*2;
if (empty($_SESSION['timestart']) AND (!isset($_SESSION['timestart'])){
// start on first page load
$_SESSION['timestart'] = time() +$twohours ;
$_SESSION['randomcode'] = '';
} elseif ($_SESSION['timestart'] < time()) {
// lets see if the time we set is smaller than time(), if so delete the
// random code so we get a new one.
$_SESSION['randomcode'] = '';
}
//Generate the random string
$chars = array("a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J","k",
"K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T","u","U","v",
"V","w","W","x","X","y","Y","z","Z","1","2","3","4","5","6","7","8","9");
$length = 8;
$textstr = "";
if (empty($_SESSION['randomcode'])) {
for ($i=0; $i<$length; $i++) {
$textstr .= $chars[rand(0, count($chars)-1)];
}
$_SESSION['randomcode'] = $textstr;
}

echo $_SESSION['randomcode'];


change the legth to the length of characters you need. this is just one way to do it. bu tI do have to make a comment. why is it that some of you guys that have this online game and you run it don't kjow how to code? you would think you would if you had a online game.

Strack
08-28-2005, 01:02 PM
thanks a lot for help.
it is not an online game. it is just a game, where we save the replays and send them to anyone. he checks if the file includes the password. because the section where we write the passwort in, isn't changeable or hackable.

but I have problems with the code. I saved the script here:

http://www.mizimace.de/nationalteam/spielarten/combo.php

probably someone can check the source code and tell me whts wrong?

_Aerospace_Eng_
08-28-2005, 01:11 PM
It looks like your web host doesn't allow php scripts to run. View the source of the page. The php can still be seen. It shouldn't be seen if your webhost was setup properly to run php.

Strack
08-28-2005, 02:22 PM
do you know a server which allows me to use php ? it has to be free

Pegasus
08-28-2005, 03:24 PM
Do a site search for "free webhosting". We have several threads on the subject.

Peg

Strack
08-31-2005, 12:34 PM
ok, thanks. I've got a webhosting now.
http://frafer5.cogia.net/combo.php

but the code still doesn't work. whats wrong with it? can someone look at it to tell me whats wrong?

_Aerospace_Eng_
08-31-2005, 12:54 PM
There was a missing ?> at the end and there needed to be another parenthese in the if statement. Try this
<?php
session_start();
$twohours = 60*60*2;
if (empty($_SESSION['timestart']) AND (!isset($_SESSION['timestart']))){
// start on first page load
$_SESSION['timestart'] = time() +$twohours ;
$_SESSION['randomcode'] = '';
} elseif ($_SESSION['timestart'] < time()) {
// lets see if the time we set is smaller than time(), if so delete the
// random code so we get a new one.
$_SESSION['randomcode'] = '';
}
//Generate the random string
$chars = array("a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J","k",
"K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T","u","U","v",
"V","w","W","x","X","y","Y","z","Z","1","2","3","4","5","6","7","8","9");
$length = 8;
$textstr = "";
if (empty($_SESSION['randomcode'])) {
for ($i=0; $i<$length; $i++) {
$textstr .= $chars[rand(0, count($chars)-1)];
}
$_SESSION['randomcode'] = $textstr;
}

echo $_SESSION['randomcode'];
?>

Strack
08-31-2005, 02:13 PM
thanks, but it still doesn't work.
And isn't it able to archive the passwords anywhere? And what do I have to write if I want to start the code at 8.pm for example?

_Aerospace_Eng_
08-31-2005, 02:34 PM
I'm not sure why it doesn't work for you. It worked on my server.

scoutt
08-31-2005, 04:50 PM
you have to run a cron job to get it to run at a specific time. if you can't do that, which I suspect you can't being on a free server, then you have to run it by yourself at 8pm. you never said you wanted to archive the numbers. look into fopen()