Here is the code, I always have the $data variable set to "" as the requests aren't received properly:
<?php
echo"<h1>J_server</h1>";
//receive requests
$data = htmlspecialchars($_POST["incoming_data"] ?? "");
//if not received properly it's defined as ""
if($data != ""){
if(file_exists("data.log")){
$file = fopen("data.log","a");
}else{
$file = fopen("data.log","w");
}
fwrite($file,$data."\n");
fclose($file);
}else{
if(file_exists("data.log")){
$file = fopen("data.log","a");
}else{
$file = fopen("data.log","w");
}
fwrite($file,"Error in recieving data!!!\n");
fclose($file);
}
?>
here is the request code:
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.post("http://localhost/j_server/server.php",data={"incoming_data":"Hello world!"})
<Response [200]>