Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a problem a simple php coding error and I cannot find out where is exactly the error, is there a way how to debug php script ?

<?php  
    $fnC = "./includes/dbConnect.php" ;   
    if(file_exists($fnC) )  {
      require_once($fnC); 
      echo "$fnC is found" ; 
    }  
    else
    { 
        echo "file does not exist : $fnC" ;  
    } 
?>
<?php  
    $fnF = "./includes/dbFunctions.php" ; 
    if(file_exists($fnF) )  {
      require_once($fnF); 
      echo "$fnF is found" ;
    }  
    else {
        echo "file does not exist : $fnF" ;  
    } 
?>

<?php
    foreach($_POST as $key => $i){
            print("$key=$i<br>");
    }


echo "script finish";
?>

Any clue where is the error ? the 2 files exists inside includes/, got the first echo of dbConnect.php (file exists) then nothing , script stops Thanks.

share|improve this question
    
Check the error_log. –  mudasobwa Dec 3 '14 at 8:38

2 Answers 2

up vote 0 down vote accepted

to check error in php you use php error reporting:

error_reporting(-1);
ini_set('display_errors', 'On');

you put that code at the top of your php code.

this will print out any error(s) that you have in your php code.

share|improve this answer
    
Thanks for your prompt answer, i m going to test now –  koul Dec 3 '14 at 8:51
    
it's working , i have found directly where is the problem. –  koul Dec 3 '14 at 8:53
    
I'm glad it helped. :) –  user3806613 Dec 3 '14 at 8:54
    
many thanks :-) –  koul Dec 3 '14 at 9:24

Sometimes, you need to maintain the order of includes! When your file being included needs some resources (like class definition, function body, etc), the file that has those resources should be included first.

However, this is not necessary if you write whole things within a single file.

If you get "failed to open stream" although you are sure your include_path is correct, check your open_basedir setting. So to avoid any strange problems and painfull debugging make sure ALL paths you use within the system have the same case everywhere, and that they correspond with the actual case of the filesystem. That includes include paths set in webserver config/php.ini, auto load config, runtime include path settings or anywhere else.

This can be simply because your included directory is outside the scope of the open_basedir which blocks php from accessing file outside you root directory(usually).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.