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条)

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统