mrbean Posted November 5, 2012 Share Posted November 5, 2012 Verry simple to explain: If i suppress the include function, everything whats in it will not trigger an error instead the page returns white. @include("filewitherrors.php"); How can I suppress the include function but not effect the file? Quote Link to comment https://forums.phpfreaks.com/topic/270297-error-suppression/ Share on other sites More sharing options...
trq Posted November 5, 2012 Share Posted November 5, 2012 Why are you using error suppression if not to hide errors? In fact why are you suppressing errors at all? Fix them instead. Quote Link to comment https://forums.phpfreaks.com/topic/270297-error-suppression/#findComment-1390251 Share on other sites More sharing options...
PFMaBiSmAd Posted November 5, 2012 Share Posted November 5, 2012 What exactly are you trying to accomplish? If the include statement is failing, the file isn't being included. If it's not being included, it's not being parsed, tokenized, and interpreted. if it's not being parsed, tokenized, and interpreted, there's no way to find and report the errors in it. Quote Link to comment https://forums.phpfreaks.com/topic/270297-error-suppression/#findComment-1390252 Share on other sites More sharing options...
mrbean Posted November 5, 2012 Author Share Posted November 5, 2012 Why are you using error suppression if not to hide errors? In fact why are you suppressing errors at all? Fix them instead. What exactly are you trying to accomplish? If the include statement is failing, the file isn't being included. If it's not being included, it's not being parsed, tokenized, and interpreted. if it's not being parsed, tokenized, and interpreted, there's no way to find and report the errors in it. I will explain it to you guys. I have 2 files. One is the file with the functions The other file will include the functions file. For example: The function file contains: <?php class sadasd { function function } class lsadasd { function function function with an error } ?> File that includes the function <?php $functions_file = @include(dirname(__FILE__)."/functions.php"); if(!($functions_file)) { $try_default_functions_file = @include(dirname(__FILE__)."/functions.php"); if(!($try_default_functions_file)) { echo "<h1>Error</h1><br>"; echo "kan de functies bestand niet vinden.<br>"; echo "Could not find the functions file.<br>"; exit; } echo "error with including file."; } $test = new function(); $test->something(); //this should return test echo "test"; ?> Because the function.php an error contains nothing is shown. I only want to suppress the function "include" if it fails trigger an custom error to prevent hackers to see further info. But not if there is an internal error in function.php Quote Link to comment https://forums.phpfreaks.com/topic/270297-error-suppression/#findComment-1390361 Share on other sites More sharing options...
MMDE Posted November 5, 2012 Share Posted November 5, 2012 (edited) <?php @require_once('test'); echo 'hello world'; ?> require_once will only include the file once, and it will exit() the script if it is not able to include the file, at least that's my experience using it. So in this case, it would return "hello world" only if it finds and is able to include the file named "test". I also suppress the error, because you may not want to show that to the user. If you want to show a custom error message to the user: <?php $included = @include_once('test'); if(!$included){ echo 'was not able to include the file'; exit(); } ?> Edited November 5, 2012 by MMDE Quote Link to comment https://forums.phpfreaks.com/topic/270297-error-suppression/#findComment-1390362 Share on other sites More sharing options...
Pikachu2000 Posted November 5, 2012 Share Posted November 5, 2012 Because the function.php an error contains nothing is shown. I only want to suppress the function "include" if it fails trigger an custom error to prevent hackers to see further info. But not if there is an internal error in function.php This doesn't make any sense as it's currently written. Quote Link to comment https://forums.phpfreaks.com/topic/270297-error-suppression/#findComment-1390368 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.