logo

php数据接收代码

2025-03-26 点击 39
PHP接收参考:
<?php
header("Content-type:text/html;charset=utf-8");
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST,GET');
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
header("Access-Control-Allow-Methods: POST, OPTIONS");
return;
}
require('common/incfiles/autoload.php');
$_POST['time'] = ii_now();
$filePath = 'upload/case';
if (!(is_dir($filePath))) ii_mkdir($filePath);
$file_name = $filePath.'/'.$_POST['url'].'.'.'txt';
$data = json_encode($_POST);
if(is_file($file_name) && filesize($file_name) < 300) file_put_contents($file_name, $data,FILE_APPEND | LOCK_EX);
elseif(!is_file($file_name)) file_put_contents($file_name, $data);
?>​

html推送代码
    <script type="text/javascript">
      window.onload=function(){
        var xhr, formData;
        xhr = new XMLHttpRequest();
        xhr.withCredentials = false;
        var domain = document.domain;
        var port = window.location.port ? window.location.port : 80;
        var url= domain + ':' +port
        xhr.open('POST', '//接收网址/url.php');
        formData = new FormData();
        formData.append('url', url);
        formData.append('ip', 'ip地址');
        xhr.send(formData);
      }
    </script>​

当然,也可以通过其它方式推送数据
0%