dongleiqiao4906 2014-05-21 05:59
浏览 49
已采纳

要求任何带有函数的php文件生成500内部服务器错误

I have a problem with require_once './DBFunctions.php'; rather server generate this error once I require any file with function even before call that function, btw my code is working correctly locally (i.e., this error only when I test scripts on server) .

My question is there any error with function keyword in php version 5.2.5 ?(I use mysql library instead of mysqli cause it's not supported on my server ).

This is my code ,

index.php

<?php  require_once "./DBfun.php" ?>
<!-- html goes here -->

DBfun.php

 <?php require_once './DBConfig.php';

 function sanitize(&$data) {
return htmlentities(strip_tags(mysql_real_escape_string($data)));}

function isExist($username) {
    $username = sanitize($username);
   $query = "SELECT * FROM `USERS` WHERE `USERNAME` ='$username' AND `STATUS`=1";
$result = mysql_query($query);
$row_cnt = mysql_num_rows($result);
$r = ($row_cnt == 1) ? "1 row matched (User Exist)" : " No matched found (User does 't      exist)";
$log = "Query: " . $query . PHP_EOL . "Result: " . $r . PHP_EOL;
//file_put_contents(LOG_FILE, $log, FILE_APPEND | LOCK_EX);
// destruct($result);
return ($row_cnt == 1) ? TRUE : FALSE;}
 ?>

I tested everything DB connection, queries (retrive data & display it), ajax requests, require files even nested requires etc.. without functions, & it worked for me, the error appear when I use (uncomment) any function =(

The error I get :

 GET http://192.168.0.36/ProjectName/index.php 500 (Internal Server Error) 
  • 写回答

2条回答 默认 最新

  • dpda53918 2014-05-21 07:09
    关注

    You can check if the file exists before you require .. however i'm sure this is not the problem.

    <?php
    
        $file = './path/to/file.php';
    
        if (is_file($file))
        {
            require_once($file);
        }
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起