0

Referring this post how-to-prevent-echo-in-php-and-catch-what-it-is-inside i am trying to get the output values from below mentioned php file but i can see still the values are getting printed in output of my php page.Any other suggestion are also welocme to get the output content from my php file to string without getting it echoed.Thanks!

<?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 code to get echo'ed values in HTML format

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);
            }
        }
Community
  • 1
  • 1
Ketan Sethi
  • 124
  • 2
  • 9

2 Answers2

2

Like in the comments of your question you can store the input in a variable. The use of the output buffer is not necessary, at least not in your example.

<?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
?>

If this does not work out for you please show us what is being echo'ed.

Philipp Palmtag
  • 1,310
  • 2
  • 16
  • 18
  • Yes by using your code nothing will be echo'ed but I need to get these variable values in String (for futher processing in my app) so i am using Javascript class[Question code edited] to get the html contents of php page – Ketan Sethi Aug 31 '16 at 12:50
  • So you are using Ajax and want to get the response from the server? – Philipp Palmtag Aug 31 '16 at 12:54
  • Yes Philipp exactly ,You got my question – Ketan Sethi Aug 31 '16 at 12:56
  • If you are using JQuery you can define the type of response. In this case you also have to send the type back what you have defined. As I recall a simple string or json are most common. The script that should deliver the response has to echo it. I modified my answer. – Philipp Palmtag Aug 31 '16 at 13:05
0

The best way to check what's going on inside running code is to use a debugger, for example xdebug. Find out how to install it and use with your IDE of choice, then place breakpoints and use watches to peek inside variables. Here's how to do it with PhpStorm.

If you cannot install a debugger, or you absolutely need to persist the values, learn the concept of logs. There is a PHP-FIG standard for logging (PSR-3) and at least one tool that implements it - for example, Monolog.

Bartosz Zasada
  • 3,762
  • 2
  • 19
  • 25