0

我有一个 php 脚本,它检查用户信息以查看是否已经参加过考试。

脚本的 Pastebin:http: //pastebin.com/z8fsrakw

实际执行处理的代码从这里开始:

$type = "Clinical";
$writeSuccess = "";
$path_to_names_file = 'storenamecli.txt';
$theemails = file($path_to_names_file);

if (strtolower($theemail) == "nurse") {
        $theemail .= rand();
}

if($fname <> "" && $lname <> "" && $theemail <> "" && $empid <> "" && $doh <> "" && (!empty($ydept) && $ydept <> "#")) {
        if(file_exists($path_to_names_file) && in_array(strtolower($theemail), $theemails)) {

它正在工作,如果用户参加考试并通过并返回尝试再次参加考试,它不会让他们这样做。但我不确定发生了什么,它允许同一个用户在不停止用户的情况下参加多项考试。

我知道脚本可能没有那么有效,但我想知道阻止“防止参加两次考试”正常工作的问题在哪里。

4

1 回答 1

1

file函数正在创建带有尾随换行符的数组值。删除它们:

$theemails = array_map('chop', file($path_to_names_file));

IE:

<?php
   $name = tempnam(sys_get_temp_dir(), "");
   file_put_contents($name, "1\n2");
   var_dump(file($name), array_map('chop', file($name)));
?>

输出:

array(2) {
  [0] =>
  string(2) "1\n"
  [1] =>
  string(1) "2"
}
array(2) {
  [0] =>
  string(1) "1"
  [1] =>
  string(1) "2"
}
于 2013-10-30T20:59:45.730 回答