Carlos Marangon wrote:
Hello!
It just works on localhost.
I am trying to make a code that deny user access when it typethe
incorrect password 3 times. The code works fine in my localhost but at
the server it alwauys says DENIED.
If you have any idea please reply me.
[]
Carlos
I'm sorry - I'm lost - I don't see how it would work since $Test6 should
never have a value everytime it starts, thus
$Test6++;
setcookie("Test6",$Test6, time()+10); // select cookie name
will mean $Test6 will always equal 1 everytime the browser refreshes...
and the cookie that is set will also be always set to 1 on that basis.
Thus, $Test6 (or $numvisits) will always be less than 6, therefore
always giving you access... Is there a time, when run locally, that you
get access denied? My guess is not...
I've relooked at your code and find it will not work as designed, even
if $Test6 had values... Hears why...
- $Test6 will always equal nothing since you've not given it a value
meaning the code in the first brace will *always* run. It will set a
cookie called Test6 to 1 and the cookie will expire in ten seconds. You
have a remark statement that says "select cookie name" - setcookie()
sets a cookie, it does not select it.
- The 'else' part of your if conditional statement never runs since
$Test6 never has a value. If it were to run, it would continually set
the cookie to the number 1, and set $Test6 to 1.
- $numvisits gets the value of $Test6 meaning you've now copied a
variable (?) and it too now equals 1.
- Your last if conditional statement says if $numvisits is less than 6
(which it is) then to grant access.
Conclusion: Access is always given...
Therefore, can you confirm that you do at some point, either locally or
on your server sometime or other get an ACCESS DENIED? My guess is you
never do, at anytime, regardless where the script is hosted.
<?php
if ($Test6 != '') {
$Test6++;
setcookie("Test6",$Test6, time()+10); // select cookie name
} else {
setcookie("Test6",1, time()+10); //Create value 1
$Test6 = 1;
}
$numvisits = $Test6;
if ($numvisits<6)
{
print("ACCESS");
}
else
{
print("DENIED");
}
?>