01-23-2008, 05:03 PM
|
#4 (permalink)
|
|
The Wanderer
Join Date: Jan 2008
Posts: 12
Thanks: 0
|
So I made 2 games 1 with cookies and 1 with sessions.
Here are the codes:
Cookies:
PHP Code:
<?php if (!isset($_COOKIE["arva"])) { setcookie('arva',rand(1,20),0); } $arvas=intval($_COOKIE["arva"]); ?>
<html> <body> <center><form action="arvamismang_cookidega.php" method="GET"> Vali arv:<input type="text" name="nr"/> <input type="submit" value="Arva"/> </form></center> <?php //I used Estonian in this script, U propally wont understand something's :D
$number=$_GET["nr"]; if (isset($arvas)) { if ($number<$arvas) { echo "<center>Paku rohkem</center>"; } if ($number>$arvas) { echo "<center>Paku vähem</center>"; } if ($number==$arvas) { echo "<center>Panid täppi!!!</center>";
} } else { echo "<center>Kuskil on viga vist :S</center>"; }
?> </body> </html>
Sessions:
PHP Code:
<?php session_start(); if (!isset($_SESSION["arva"])) {
$_SESSION["arva"]=rand(1,20); } $arvas=intval($_SESSION["arva"]); ?>
<html> <body> <center><form action="arvamismang_cookidega.php" method="GET"> Vali arv:<input type="text" name="nr"/> <input type="submit" value="Arva"/> </form></center> <?php //I used Estonian in this script, U propally wont understand something's :D $number=$_GET["nr"]; if (isset($arvas)) { if ($number<$arvas) { echo "<center>Paku rohkem</center>"; } if ($number>$arvas) { echo "<center>Paku vähem</center>"; } if ($number==$arvas) { echo "<center>Panid täppi!!!</center>"; unset($_SESSION["arva"]); } } else { echo "<center>Kuskil on viga vist :S</center>"; }
?> </body> </html>
Big thanks to RobertK for help.
Maybe U can explane to me why thosent it change the number with this code:
PHP Code:
<?php if (!isset($_COOKIE["arva"])) { setcookie('arva',rand(1,20),0); } $arvas=intval($_COOKIE["arva"]); ?>
But those change every time in this code:
PHP Code:
$arva=(rand(1,20)); if (isset($arva)) { //Kas genereeriti arv? Kui jh siis jätkame. if ($number<$arva) { echo "Vähe pakkusid"; }
Now I have no idea what do too next.
Last edited by karq : 01-23-2008 at 08:36 PM.
|
|
|
|