Php 检查文件中的事件不起作用

Php 检查文件中的事件不起作用,php,html,Php,Html,我有一个php脚本,它检查用户信息,看看是否已经参加了考试 脚本的粘贴库: 实际执行处理的代码从这里开始: $type = "Clinical"; $writeSuccess = ""; $path_to_names_file = 'storenamecli.txt'; $theemails = file($path_to_names_file); if (strtolower($theemail) == "nurse") { $theemail .= rand(); } i

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

脚本的粘贴库:

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

$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)) {
$type=“临床”;
$writeSuccess=“”;
$path_to_names_file='storenamecli.txt';
$theemails=file($path\u to\u names\u file);
如果(strtolower($theemail)=“护士”){
$theemail.=rand();
}
如果($fname“”&&$lname“”&&$theemail“”&&$empid“”&&$doh“”&&(!empty($ydept)&&&$ydept“#”){
如果(文件存在($path_to_names_file)&&in_数组(strtolower($theemail),$theemails)){
它是有效的,如果一个用户参加考试并通过考试,然后返回尝试再次参加考试,它将不会让他们参加。但我不确定发生了什么,它允许同一用户在不停止用户的情况下参加多个考试


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

文件函数正在创建带有尾随新行的数组值。删除它们:

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


您似乎在使用
$theemail
然后使用
$theemail
。没有代码显示
$theemail
的来源。您是否遗漏了它?请阅读文档-它返回一个数组,而不是一个字符串。尝试一下。IMO:对于这样的事情,使用DB会更容易管理。@SiKni8我理解。只需给“我的2美分”-)@SiKni8谢谢,我很高兴你找到了干杯。
<?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"
}