php会话和cookie生命周期

时间:2015-07-16 11:53:58

标签: php

List<string> guiIdentifiers = new List<string>{"x", "y", "z", "x", "y"};

string input = "foo () () () () () ()";

string[] splitPath = Regex.Split(input, @"(\(\))");

for (int i = 0; i < splitPath.Length; i++)
{
  if (splitPath[i] == "()" && guiIdentifiers.Count > 0)
  {
    splitPath[i] = string.Format("({0})", guiIdentifiers.First()); 
    guiIdentifiers.Remove(guiIdentifiers.First());
  }
}
string result = string.Join("", splitPath);

以上代码应该在失败尝试次数超过3后限制登录访问,但cookie生命周期不适用,当我运行代码时,它运行正常,但在第一次运行时生成错误....请检查代码并帮助......

1 个答案:

答案 0 :(得分:0)

您需要初始化$_SESSION["FAIL"],以便在向变量

添加1时执行此操作
if(isset($_SESSION["FAIL"])) {
    $_SESSION["FAIL"]++;
} else {
    $_SESSION["FAIL"] = 1;
}

所以只为你

<?php
ini_set("session.cookie_lifetime",10);
session_start();
if(isset($_SESSION["BAN"])){
echo "<font color='red'>you can no longer          login for this session,<font     color='blue'>please restart your browser</    font></font>";
}else{
if(isset($_POST["submit"])){
$name=$_POST["name"];
if($name!="emmy"){
if(isset($_SESSION["FAIL"])) {
    $_SESSION["FAIL"]++;
} else {
    $_SESSION["FAIL"] = 1;
}
echo "<font color='red'>wrong     password...try again </font><br>";
//echo "wrong by ".$_SESSION["FAIL"]." time(s)<br>";
}else{
echo "access granted....
<br> ";
}
if(isset($_SESSION["FAIL"]) && $_SESSION["FAIL"]>3){
$_SESSION["BAN"]="bad";
echo "you
 entered the wrong password too many     times";
//header("location:pat.php");
}
}
echo <<< DOC
<form action="form.php" method="post">
<input type="text"name="name"/>
<input type="submit"name="submit"/>
</form>
DOC;
}
?>