2

I write some log file on my server after the submit data from other server automatically when my payment is success. my cookies log file are working well but after the loop it not working.

<?php
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        $roomname          = $_POST['roomname'];
        $cartinfo          = $_POST['cartinfo'];    

        $str = substr_replace($cartinfo, $roomname, 2, 0);
        $arrs = explode(",", $str);
        $numArrs = array_shift($arrs);
        array_walk($arrs, function(&$val, $key) {  $val = explode(';',$val); });

        //work at this step 

        // $payload ="hello";
        // $steal = fopen("1.txt", "a");
        // fwrite($steal, $payload ."\n"); 
        // fclose($steal);

        $ans = array();

        for($i=0; $i<$numArrs; $i++) {
            $ans[] = array_column($arrs, $i);
        }

        //Not working.... 
        $payload ="hello";
        $steal = fopen("1.txt", "a");
        fwrite($steal, $payload ."\n"); 
        fclose($steal);

        foreach ($ans as $key => $value) {
            $roomname = $value[0];
            $roomqty  = $value[1];
            $arrival  = $value[2];
            $departure= $value[3];
            //insert data into database
        }           
    }

?>

The post method will be submit by other server automatically. I goal is to insert data in the loop if the payment is succes..

Min Ko Ko
  • 131
  • 1
  • 2
  • 12

1 Answers1

0

I think that your cookies aren't working well after the loop because you are echoing some content in it:

echo $roomname = $value[0];
echo $roomqty  = $value[1];
echo $arrival  = $value[2];
echo $departure= $value[3];

The echos will send data to the client so that you are not able to call header(), setcookie() etc.

Please have a look at: setcookie, Cannot modify header information - headers already sent

Community
  • 1
  • 1
mario.van.zadel
  • 2,919
  • 14
  • 23