dsj2222222 2016-10-31 21:51
浏览 147
已采纳

php将自定义数据发送到php web服务器并将其保存到文件中

I know that when requesting a webpage, there is different ways of requesting it. Get, Post, PUT, Patch, Delete and a few more. But I wonder how I could send like a text file including multiple lines to a php web server, and get that server to catch the message and save it? I managed to do this with 1 line, and looked like this:

GET /SECRET-MESSAGE HTTP/1.1" 404 2306

But it only made me request a directory that doesn't exists and multiple lines would be problematic which makes this method really stupid.

I got inspired by this video, where he shows the rubber ducky sending some kind of custom request to a php webserver. (No, I'm not gonna steal passwords) I'm not totally sure what type of request it does, or how it sends the data to the server. The server then catches it by doing the following code:

file_put_contents($file, file_get_contents("php://input"));

But I simply doesn't get it to work. When I look up the file, it says 0 bytes and doesn't include anything.

The code I'm using so far is this

$file = "log/" . date("m.d.y") . "/[" . $_SERVER['REMOTE_ADDR'] . "] " . date("H:i:s") . ".lll";
$content = file_get_contents("php://input");
file_put_contents($file, $content);

There is nothing wrong with permissions because I've tested with some other text and I've set all permission allowed to everyone: "0777" Reason I want to do this, is to make a kind of a text saving cloud where I can send my notes to my server. If I remember something I want to write down, I could just send it to the server, and look it up later.

Is it anything I'm doing wrong here or not noticing? Please help.

  • 写回答

1条回答 默认 最新

  • douyi02577 2016-10-31 23:28
    关注

    php://input reads from the request body of a POST request

    http://php.net/manual/en/wrappers.php.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。