douxi9245
2014-11-02 22:07
浏览 67
已采纳

使用fopen和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. 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

anti_injection($_POST['email']);

图片转代码服务由CSDN问答提供 功能建议

我在写文件VarLog.txt时遇到问题,它不是只读的(在属性中),我 我试图将变量或SQL查询作为字符串写入我创建的日志文件中,我还写了一个检查以查看VarLog是否存在,如果不存在,则创建它。 这是代码

  if(!file_exists(“VarLog.txt”)){
 $ fh = fopen(“VarLog.txt”,“w”)或die(  “无法打开文件”); 
 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); 
返回$ sql; 
} 
   
 
 

$ _POST变量的示例 < pre> anti_injection($ _ POST ['email']);

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • drjltlm156790 2014-11-02 22:17
    已采纳

    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.
    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).
    点赞 打赏 评论

相关推荐 更多相似问题