duanbichou4942 2019-01-25 18:02
浏览 54

php短打标签是避免缓冲区使用和捕获

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.

Result

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.
}
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘