Get php values

0

I need to get values in php, the problem is that I do not know the name of the variables that are sent, is there any way to get the name or variables with php? the code is as follows

$deviceID = $_SERVER['HTTP_DEVICEID'];

$rawPostData = "DeviceID: ".$deviceID."\n";
$rawPostData .= print_r($GLOBALS['HTTP_RAW_POST_DATA'], TRUE);

$filedatetime=date('ymdHis');
$rawPostFile = "data/playlog_".$filedatetime.".txt";
$rawPostHandler = fopen($rawPostFile, 'w') or die('Could not open file!');
fwrite($rawPostHandler, $rawPostData) or die('Could not write to file');
fclose($rawPostHandler);

$fileStream .= $rawPostData;

wanting to get data with global no longer receives, apparently no longer sent with that name, but I have no way of knowing how to send in advance thanks for the help

    
asked by Isai Lopez 02.11.2017 в 00:40
source

1 answer

0

Your code has some problems.

Let's list them:

1. Misuse of print_r

print_r is not used to store values in variables, but to print values already stored.

Therefore this code is incorrect:

$rawPostData .= print_r($GLOBALS['HTTP_RAW_POST_DATA'], TRUE);

2. HTTP_RAW_POST_DATA is obsolete

According to the PHP Manual :

  

HTTP_RAW_POST_DATA This feature was declared OBSOLETE in   PHP 5.6.0 and ELILMINED as of PHP 7.0.0.

Therefore, if you are using PHP 7, you will not get anything with this:

$rawPostData .= print_r($GLOBALS['HTTP_RAW_POST_DATA'], TRUE);

HTTP_RAW_POST_DATA has been replaced by php://input as the PHP Manual says :

  

php://input is a read-only flow that allows you to read data from the   requested body. In the case of POST requests, it is preferable to use    php://input instead of $HTTP_RAW_POST_DATA since it does not depend on   special php.ini directives. However, when it is not generated   automatically $HTTP_RAW_POST_DATA , it is an alternative that   makes less intensive use of memory than activating    always_populate_raw_post_data php://input is not available with    enctype="multipart/form-data .

3. The case of HTTP_DEVICEID does not appear documentation about it

Obviously you try to get the device id. I did not find data about that. In SO in English they suggest reading the User-Agent data to obtain it or using third-party libraries.

We will apply the corrections mentioned:

//$deviceID = $_SERVER['HTTP_DEVICEID']; 

//$rawPostData = "DeviceID: ".$deviceID."\n";  ver como obtenerlo
$rawPostData = file_get_contents("php://input");

/*Aquí puedes revisar lo que hay en $rawPostData con print_r*/
print_r($rawPostData);

$filedatetime=date('ymdHis');
$rawPostFile = "data/playlog_".$filedatetime.".txt";
$rawPostHandler = fopen($rawPostFile, 'w') or die('Could not open file!');
fwrite($rawPostHandler, $rawPostData) or die('Could not write to file');
fclose($rawPostHandler);

$fileStream .= $rawPostData; 
    
answered by 02.11.2017 / 01:19
source