Question

I have this code:

function WriteLog($offer,$values) {
    $Filename = "./".$offer.date('Ymd').".txt";
    $fh = fopen($Filename, 'a') or die("can't open file");
    $filecontent = $values;
    $filecontent .= PHP_EOL;
    fwrite($fh,$filecontent);
    fclose($fh);
}

$aff = "100";

if (isset($HTTP_RAW_POST_DATA)) {
    echo $aff;

    WriteLog('events',$aff);

}

Here's the problem: The $aff variable is not accessible. Echoing the $aff inside the if ISSET statement doesn't display the value of the $aff. What's probably causing this? How can I access the value of the $aff variable? Note that the WriteLog() function was executed but the $aff doesn't have a value. Please help me with this. Thanks!

Was it helpful?

Solution

Its just an idea to check the value of $aff wether it goes inside if check or not.

 $aff = "100";

 if (isset($HTTP_RAW_POST_DATA)) {
    var_dump($aff);
    WriteLog('events',$aff);
 }
 else{
    var_dump($aff); 
 }

OTHER TIPS

$HTTP_RAW_POST_DATA contains the raw POST data.

in your case $HTTP_RAW_POST_DATA doesn't contain any value, so your if condition failed and not print the echo $aff; value.

$aff = "100";

if (isset($HTTP_RAW_POST_DATA)) {
  echo $aff;

  WriteLog('events',$aff);
 }else{
   echo "HTTP_RAW_POST_DATA not set";
}

$HTTP_RAW_POST_DATA requires an ini value to be set, using the input stream should work without any special ini settings and is also the 'prefered' method.

you need to use an alternative method

$postData = file_get_contents('php://input')

the documentation is here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top