redarrow Posted February 29, 2008 Share Posted February 29, 2008 how can i get a session to match a varable... as soon as i post the varable $res, the session changes so how do you do it thank you... <?php session_start(); $_SESSION['number']=rand(000000,999999); $res=$_SESSION['number']; if($_POST['submit']){ $res=$_POST['res']; if($res==$_SESSION['number']){ echo "correct"; } } ?> <form method="POST" action=""> <br><br> <?php echo $_SESSION['number']; ?> <br><br> please enter number <br></br> <input type="text" name="res"> <br><BR> <input type="submit" name="submit" value="SEND"> </form> Link to comment https://forums.phpfreaks.com/topic/93699-how-to-get-two-numbers-match-with-a-posting-form/ Share on other sites More sharing options...
tinker Posted February 29, 2008 Share Posted February 29, 2008 Because you reset the 'number' each time (at the start), you'll need a second variable, either use 'res' or 'last_number': $_SESSION['last_number'] = $_SESSION['number']; P.S. What are you trying to do? Link to comment https://forums.phpfreaks.com/topic/93699-how-to-get-two-numbers-match-with-a-posting-form/#findComment-480071 Share on other sites More sharing options...
redarrow Posted February 29, 2008 Author Share Posted February 29, 2008 a easy gotcha, can you show me the example you posted cheers...... Link to comment https://forums.phpfreaks.com/topic/93699-how-to-get-two-numbers-match-with-a-posting-form/#findComment-480075 Share on other sites More sharing options...
tinker Posted February 29, 2008 Share Posted February 29, 2008 same as calculating a time step in a game loop... what you trying to achieve? Link to comment https://forums.phpfreaks.com/topic/93699-how-to-get-two-numbers-match-with-a-posting-form/#findComment-480080 Share on other sites More sharing options...
redarrow Posted February 29, 2008 Author Share Posted February 29, 2008 secuity form like gotcha if the numbers match goto the page lol example but the session always matches i need it to match on posting <?php session_start(); $_SESSION['number']=rand(000000,999999); $_SESSION['last_number']=$_SESSION['number']; if($_POST['submit']){ $res=$_SESSION['last_number']; if($res==$_SESSION['number']){ echo "correct"; } } ?> <form method="POST" action=""> <br><br> <?php echo $_SESSION['number']; ?> <br><br> please enter number <br></br> <input type="text" name="res"> <br><BR> <input type="submit" name="submit" value="SEND"> </form> Link to comment https://forums.phpfreaks.com/topic/93699-how-to-get-two-numbers-match-with-a-posting-form/#findComment-480082 Share on other sites More sharing options...
tinker Posted February 29, 2008 Share Posted February 29, 2008 sorry the 'gotcha' thing flew straight by me (self taught)... Change this bit to: if($res==$_SESSION['last_number']){ echo "correct"; } } The way I do is to generate a gotcha string and a md5/salt of it, store both in a table, then send the md5 in the page, which calls a gd image gen page passing the md5, this then looks up the gotcha string in the table using the md5. This way the gotcha string is never sent in plain text... Link to comment https://forums.phpfreaks.com/topic/93699-how-to-get-two-numbers-match-with-a-posting-form/#findComment-480092 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.