php - 如何通过php将数据发送到另一台计算机?
问题描述
我想知道是否有办法将数据从index.php
一台计算机上index.php
打开的数据发送到另一台计算机上打开的数据。我不知道该怎么做。
解决方案
是的。
简单/懒惰的方式:只需执行远程获取请求
// example1.com/index.php
file_get_contents("http://example2.com/index.php?your_data=goes_here");
// example2.com/index.php
$your_data = $_GET['your_data'];
更难/更好的方法:使用 curl 发送 post 请求
// on example1.com/index.php
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, "http://example2.com/index.php");
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, 'your_data' => 'goes_here');
$result = curl_exec($ch);
curl_close($ch);
// on example2.com/index.php
$your_data = $_POST['your_data'];
警告:任何人都可以使用这些方法中的任何一种将他们想要的任何内容输入到您的脚本中。确保加密和/或验证您以这种方式传输的任何数据。
推荐阅读
- serverless-framework - Serverless Webpack 在 ZIP 包中生成空文件
- powershell - Powershell not running on cmd
- flutter - Flutter/Dart Compare multiple Lists and generate list with elements containd in all given lists
- r - How to filter timestamps of one data frame based on timestamps from another?
- node.js - How to reproduce a websocket connection intercepted by mitmproxy?
- javascript - 反应表单输入值未正确显示
- amazon-dynamodb - Verify dynamodb is healthy
- c - shm_unlink 的行为
- laravel - Laravel Dusk 很慢
- c - 杂项函数在 C 中经历隐式转换?