php - Modulus of a string -


i in puzzling situation. intially when user visits particular page, popup shown. user can accept or decline it. when user declines it, after 5 page visits, pop again shown user. part working perfectly. when user clicks ok, ajax call made , session variable set ok. lets $_session['count'] = 0. have 2 condition statements.

if($_session['count']%5 === 0) { // } elseif($_session['count'] === "ok") { //  } 

now when user press ok, ajax call made updating $_session['count'] = "ok". when user again reloads page, condition if($_session['count']%5 === 0) gets true though $_session['count'] ok. later after experimenting, came know in php able divide or find modulus string number result in zero. how can handle this?

you can use is_numeric check if count or 'ok'

http://php.net/manual/en/function.is-numeric.php

if(is_numeric($_session['count']) && $_session['count']%5 === 0) { // } elseif($_session['count'] === "ok") { //  } 

though generally, set ok value of different variable in $_session best practice. if looking @ code find odd see called count having string value.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -