簡體   English   中英

如何防止PHP中的回聲並獲取其中的內容?

[英]How to prevent echo in PHP and get what it is inside?

引用這篇文章如何防止回聲在PHP中並捕捉到它在里面是什么,我正試圖從下面提到的PHP文件中獲取輸出值,但我仍然可以看到這些值正在打印中我的php頁面的輸出。其他任何建議也都是welocme,它可以將我的php文件的輸出內容轉換為字符串,而不回顯它。謝謝!

<?php include('Crypto.php')?>
<?php       
    $workingKey='XXXX';     //Working Key should be provided here.
    $encResponse=$_POST["encResp"];         //This is the response sent by the Server
    $rcvdString=decrypt($encResponse,$workingKey);      //Crypto Decryption used as per the specified working key.      
    $order_status="";
    $order_id=0;        
    $decryptValues=explode('&', $rcvdString);
    $dataSize=sizeof($decryptValues);
    echo "<center>";    
    for($i = 0; $i < $dataSize; $i++) 
    {
        $information=explode('=',$decryptValues[$i]);
        if($i==0)   $order_id = $information[1];
        if($i==1)   $tracking_id = $information[1];
        if($i==3)   $order_status = $information[1];
    }
       ob_start();
       echo $order_id."_";  
       $out1 = ob_get_contents();
      echo $tracking_id."_";
      $out2 = ob_get_contents();
      echo $order_status;
      $out3 = ob_get_contents();
      ob_end_clean();
      var_dump($out3);
?>

JAVASCRIPT代碼以HTML格式獲取回顯值

class MyJavaScriptInterface
        {
            @JavascriptInterface
            @SuppressWarnings("unused")
            public void processHTML(final String html)
            {


               String order_page = ""+Html.fromHtml(html);//process php output to html

               String CCAvenueOrder_id = order_page.split("\\_")[0];
               String CCAvenueTacking_id=order_page.split("\\_")[1];
               String CCAvenueOrderStatus=order_page.split("\\_")[2];


                // process the html as needed by the app
                String status = null;

                if(html.indexOf("Failure")!=-1){
                    status = "Transaction Declined!";
                }else if(html.indexOf("Success")!=-1){
                    status = "Transaction Successful!";
                }else if(html.indexOf("Aborted")!=-1){
                    status = " Transaction Cancelled!";
                }else{
                    status = "Status Not Known!";
                }
                //Toast.makeText(getApplicationContext(), status,     Toast.LENGTH_SHORT).show();
                Intent intent = new     Intent(getApplicationContext(),StatusActivity.class);

                startActivity(intent);
            }
        }

就像在問題注釋中一樣,您可以將輸入存儲在變量中。 不需要使用輸出緩沖區,至少在您的示例中是不需要的。

<?php       
    $workingKey='XXXX';     //Working Key should be provided here.
    $encResponse=$_POST["encResp"];         //This is the response sent by the Server
    $rcvdString=decrypt($encResponse,$workingKey);      //Crypto Decryption used as per the specified working key.      
    $order_status="";
    $order_id=0;        
    $decryptValues=explode('&', $rcvdString);
    $dataSize=sizeof($decryptValues);
    $output = "<center>";    
    for ($i = 0; $i < $dataSize; $i++) {
        $information=explode('=',$decryptValues[$i]);
        if($i==0)   $order_id = $information[1];
        if($i==1)   $tracking_id = $information[1];
        if($i==3)   $order_status = $information[1];
    }
    $output .= $order_id."_";  
    $output .= $tracking_id."_";
    $output .= $order_status;
    echo $output; // response for ajax request as simple string
?>

如果這對您不可行,請告訴我們正在回顯的內容。

檢查正在運行的代碼內部發生了什么的最好方法是使用調試器,例如xdebug 了解如何安裝它並與您選擇的IDE一起使用,然后放置斷點並使用監視表來查看內部變量。 這是使用PhpStorm的方法

如果您無法安裝調試器,或者絕對需要保留值,請學習日志的概念。 有一個用於日志記錄的PHP-FIG標准( PSR-3 )和至少一個實現該標准的工具-例如Monolog

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM