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']);
  • 写回答

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).
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度