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> Quote Link to comment 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? Quote Link to comment 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...... Quote Link to comment 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? Quote Link to comment 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> Quote Link to comment 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... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.