简体   繁体   English

fopen和fwrite PHP的问题

[英]Issue with fopen and fwrite PHP

I'm having issues writing to the file VarLog.txt, It's not read only (In properties), I'm trying to write the Variable or SQL Query as a string in the logs file that I created, I also wrote a check to see if VarLog exists, and if it doesn't, make it. 我在写入文件VarLog.txt时遇到问题,它不是只读的(在属性中),我正在尝试将变量或SQL查询作为字符串写入我创建的日志文件中,我还写了一个检查查看VarLog是否存在,如果不存在,则进行创建。 Here's the Code 这是代码

   if (!file_exists( "VarLog.txt")) {
    $fh = fopen("VarLog.txt", 'w') or die("can't open file");
    fclose($fh);
}
function anti_injection($sql) {
   $fp = fopen("VarLog.txt", "a+");  
   $sql = preg_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/"),"",$sql);
   $sql = trim($sql);
   $sql = strip_tags($sql);
   $sql = addslashes($sql);
   fwrite($fp, "SQL Query/String: $sql"); 
   fclose($fp);
   return $sql;
}

An Example of a $_POST variable $ _POST变量的示例

anti_injection($_POST['email']);

The code itself doesn't present any errors, other than the first check if the file exists and creating it is redundant. 除了首先检查文件是否存在并创建冗余文件外,代码本身不会出现任何错误。

  1. Remove the file VarLog.txt if it exists to rule out ownership problems. 删除文件VarLog.txt(如果存在)以排除所有权问题。
  2. Check what your working directory is. 检查您的工作目录是什么。 Your path right now isn't an absolute path, so files will be written relative to whatever the current working directory is (use getcwd() to find out what that path is, and check there). 现在您的路径不是绝对路径,因此将相对于当前工作目录的内容写入文件(使用getcwd()找出该路径是什么,然后在此处检查)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM