I have this php script to capture content of included files:
ob_start();
include FILEROOT . $Path;
$File = ob_get_contents(); // get contents of buffer
ob_end_clean();
but inside the example file /path/file.php
this example;
<div id="Modal-js">
<?php
#Control de opciones restaurar Contraseña del usuario
$opt_id_req='';
$opt_id_req_req='';
$opt_carnet='';
$opt_carnet_req='';
$opt_email ='';
$opt_email_req ='';
$opt_username='';
$opt_username_req='';
?>
<!-- Modal para Password reset tipo Info del Servidor -->
<div class="modal inmodal fade" id="passwordreset" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-xs">
<div class="modal-content animated bounceInRight">
<form name="f-gen-userreset" id="formuserreset">
<div class="modal-header bg-success">
<button type="button" class="close" data-dismiss="modal"><i class="fas fa-window-close text-white"></i><span class="sr-only">Close</span></button>
<h4 class="modal-title">Recuperación de Contraseña.</h4>
</div>
<div class="modal-body">
<p>Por Favor Ingrese el Dato Solicitado del Sistema.</p>
<p class="text-warning">El Sistema le enviara una nueva contraseña; Cuando entre al sistema, se le Solicitara que Cambie su Contraseña.</p>
<div class="form-group row notvalidres <?=@$opt_id?> ">
<label>ID</label>
<input type="text" id="i-text-id-reset" name="i-text-id-reset" class="form-control" <?=@$opt_id_req?>>
</div>
<div class="form-group notvalidres <?=@$opt_carnet?> ">
<label>Carnet</label>
<input type="text" id="i-text-carnet-reset" name="i-text-carnet-reset" class="form-control" <?=@$opt_carnet_req?>>
</div>
</div>
<div class="modal-footer" data-html2canvas-ignore="true">
<button type="button" class="btn btn-outline btn-cls-info" name="p-adjust" data-target="f-gen-userreset">Recuperar Contraseña</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
The problem is that I'm not printing anything in php code. However, apparently the php sends to print the buffer for some reason.
this problem occur with print short tag implementation on include file.
UPDATE
add to this scenario the use of an Error handler, to which you try to place an exit;
in each function.
https://stackoverflow.com/a/54259189/10771503
<?php
declare(strict_types=1);
ini_set('session.gc_maxlifetime', '0');
ini_set('session.use_only_cookies', '1');
ini_set('session.cookie_httponly', '1');
ini_set('allow_url_fopen', '1');
ini_set('allow_url_include', '1');
ini_set('error_reporting', '1');
ini_set('display_errors', '0');
error_reporting(E_ALL);
register_shutdown_function("ShutdownHandler");
set_error_handler("ErrorHandler");
set_exception_handler("ExeptionHandler");
function ShutdownHandler() {
$CheckError = error_get_last();
if ($CheckError != null) {
$ErrorHandler = "<b>File:</b> " . $CheckError['file'] . '<br>' .
"<b>Line:</b> " . $CheckError['line'] . '<br>' .
"<b>Desc:</b> <br>" . $CheckError['message'] . '<br>';
echo $ErrorHandler;
exit;#if i remove this. the script and bufer work fine.
}
}
function ErrorHandler($error_level, $error_message, $error_file, $error_line, $error_context) {
$ErrorHandler = "<b>File:</b> " . $error_file . '<br>' .
"<b>Line:</b> " . $error_line . '<br>' .
"<b>Desc:</b> <br>" . $error_message . '<br>';
echo $ErrorHandler;
exit; #if i remove this. the script and bufer work fine.
}
function ExeptionHandler($e) {
$ErrorHandler = "<b>File:</b> " . $e->getFile() . '<br>' .
"<b>Line:</b> " . $e->getLine() . '<br>' .
"<b>Desc:</b> <br>" . $e->getMessage() . '<br>';
echo $ErrorHandler;
exit; #if i remove this. the script and bufer work fine.
}
?>