RE: Guess random number 04-02-2017, 08:24 PM
#9
Here's my final code i'll be glad to get comments if there's anything i should fix in my code.
Spoiler:
Code:
<?php
session_start();
if(isset($_SESSION["hasStarted"])==false){
$_SESSION["number"]=rand(0,100);
$_SESSION["hasStarted"]=true;
$_SESSION["tries"]=0;
}
?>
<html>
<head>
</head>
<body>
<div><p>Guess the hidden number between 0 and 100</p>
<form method="post" action="random.php">
<input type="text" name="number"/>
<input type="submit" value="Guess"/>
</form></div>
<?php
if($_POST){
$_SESSION["tries"]++;
if($_POST["number"]==$_SESSION["number"]){
$_SESSION["hasStarted"]=false;
?><script>alert("You've guessed the hidden number after "+<?php echo $_SESSION["tries"];?>+" tries");</script>
<div><a href="random.php">PLAY AGAIN</a></div>
<?php unset($_SESSION["hasStarted"])?>
<?php
$_SESSION["tries"]=0;
}
else{?>
<script><?php if($_SESSION["number"]<$_POST["number"]){?>alert("Hidden number is smaller");<?php }?></script>
<script><?php if($_SESSION["number"]>$_POST["number"]){?>alert("Hidden number is bigger");<?php } ?></script>
<?php }} ?>
</body>
</html>Everyone should learn how to code, it teaches you how to think.
You don't have to be a Genius to know how to code you just need to be determined.
The computer is incredibly fast, accurate, and stupid; man is unbelievably slow, inaccurate, and brilliant; together they are powerful beyond imagination.





![[+]](https://sinister.li/images/modern/collapse_collapsed.png)