Why value doesn't want to increment when I submit a post

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Why value doesn't want to increment when I submit a post



I'm making a login attempt checker, so if user inputs wrong key (witch was send via email) then It add +1 on the attempt meter. I stored it in a session did quite a lot of research but it just doesn't work. here is my PHP code.


session_start();
$_SESSION['poskusi'] = 0;
$kljuc = $_SESSION['rand_kljuc'];

if(isset($_POST['vpis_kljuc']))
$vpis_kljuc = $_POST['vpis_kljuc'];
if($vpis_kljuc == $kljuc)
echo "You are in";

else
echo "Wrong key";
$_SESSION['poskusi']+1;
if($_SESSION['poskusi'] == 3)
echo "locked";







ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); anything from this?
– Funk Forty Niner
Aug 8 at 14:50


ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);





$_SESSION['poskusi']+1; should be $_SESSION['poskusi']+=1;
– Iłya Bursov
Aug 8 at 14:50


$_SESSION['poskusi']+1;


$_SESSION['poskusi']+=1;





$_SESSION['poskusi']+1 should be $_SESSION['poskusi'] += 1; or $_SESSION['poskusi']++;
– AymDev
Aug 8 at 14:50


$_SESSION['poskusi']+1


$_SESSION['poskusi'] += 1;


$_SESSION['poskusi']++;





Also, you're setting $_SESSION['poskusi'] to 0 every time the PHP script is loaded.
– BenM
Aug 8 at 14:51


$_SESSION['poskusi']


0




1 Answer
1



You are setting the counter to 0 every time the page loads.


0



Try this:


if(!isset($_SESSION['poskusi']))
$_SESSION['poskusi'] = 0;



You are also incrementing it wrong. It should be



$_SESSION['poskusi']++; or


$_SESSION['poskusi']++;



$_SESSION['poskusi']+=1; if you prefer.


$_SESSION['poskusi']+=1;





code doesn't work for me I added session_destroy() and then just redirect it to login
– ribicem
Aug 8 at 15:17






what isn't working?
– Bojan Srbinoski
Aug 8 at 15:20





Well now it increment nicely but when I add function above it doesn't set $_SESSION['poskusi'] to 0 but it just keep going
– ribicem
Aug 8 at 15:22





That's because the variable is already set. When do you want it to be set to 0?
– Bojan Srbinoski
Aug 8 at 15:22





After 3 tries then client will have to wait idk 5-10 min then I'll set $_SESSION['poskusi'] to 0
– ribicem
Aug 8 at 15:25






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

React Native Navigation and navigating to another Screen problem