adv Posted December 19, 2007 Share Posted December 19, 2007 edit :dunno if it`s really a count problem but that`s all my english hello in a form if u submit the data ... and the user is wrong i saw on some webpages .. You have 4 chances . how do i do it when a user press submit button and the data is incorrect to apear " you have 4 chances .. 3 chances .. 2 .. 1 Quote Link to comment Share on other sites More sharing options...
chigley Posted December 19, 2007 Share Posted December 19, 2007 Sessions Read up on it, you learn better that way. Quote Link to comment Share on other sites More sharing options...
adv Posted December 19, 2007 Author Share Posted December 19, 2007 yep i`m lost Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 19, 2007 Share Posted December 19, 2007 you replied in 2 minuet google php sessions and read. Quote Link to comment Share on other sites More sharing options...
adv Posted December 19, 2007 Author Share Posted December 19, 2007 this is help ??? to read google can someone give me an example and explain Quote Link to comment Share on other sites More sharing options...
chigley Posted December 19, 2007 Share Posted December 19, 2007 If we laid it on a plate for you.. what would you learn from it? Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 19, 2007 Share Posted December 19, 2007 I just made this for you to trie so you can understand sessions.. if you enter the name redarrow you get the congratulations... <?php session_start(); if($_POST['submit']){ $username=$_POST['username']; $name="redarrow"; if($username==$name){ echo "Congratulations you win!"; unset($_SESSION['count']); echo "<br><br><a href=" .$_SESRVER['PHP_SELF']. ">Please try agin</a>"; exit; }else{ if (empty($_SESSION['count'])) { $_SESSION['count'] = 1; } else { $_SESSION['count']++; if($_SESSION['count']==4){ echo " sorry you lose!"; unset($_SESSION['count']); echo "<br><br><a href=" .$_SESRVER['PHP_SELF']. ">Please try agin</a>"; exit; } } } } ?> <html> <title>Session Count test</title> <head> </head> <body> <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" > <br> you have tried <?php echo $_SESSION['count']; ?> times! <br><br> Please enter your name <br><br> <input type="text" name="username"> <br><br> <input type="submit" name="submit" value="SEND"> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
adv Posted December 19, 2007 Author Share Posted December 19, 2007 redarrow in ur code it doesn`t count .. if u click submit a couple of times it stays to 1 times i tried soemthing like u <? session_start(); if(isset($_POST['submit'])) { if (empty($_SESSION['count'])) { $_SESSION['count']=4; }else{ $_SESSION['count']--; } } if($_SESSION['count']==0){ echo "blocked"; } echo $_SESSION['count']; ?> but it doesn`t drop from 4 .. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 19, 2007 Share Posted December 19, 2007 try this <?php session_start(); if (!isset($_SESSION['counter'])) { $_SESSION['counter'] = 4; } else { $_SESSION['counter']--; } if ($_SESSION['counter'] < 1) { echo "<h1>no more tries</h1>"; } else { echo "<h1>you got ".$_SESSION['counter']." left<h1>"; } echo "<a href='{$_SERVER['PHP_SELF']}'>Test Counter</a>"; ?> 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.