通过 PHP 通过另一个网站发送数据


Sending Data over another website via PHP

所以我什至不知道这是否可能,但基本上我想为客户创建一个后台,处理他在两个市场(play.com 和亚马逊)上的销售。

我可以使用 PHP 填写表单和发送数据吗?我可以登录网站以抓取日期(新订单等)

我在那里找到了我的部分答案:创建一个"机器人"来填充表单中的一些页面

我怀疑PHP不是这方面的语言,任何建议将不胜感激!

答案的另一部分就在这里。您可以使用cURL来实现这一点。

使用cURL您可以登录网站。此处的示例示例为您提供了一个启动。

<?php
$username="name@mail.com"; 
$password="mypassword"; 
$url="http://www.myremotesite.com/login.php"; 
$postdata = "email=".$username."&password=".$password; 
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_REFERER, $url); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec ($ch); 
echo $result;  
curl_close($ch);

您可以尝试SimpleTest,但通常大型服务会提供API接口来与它们进行交互。

$q="INSERT INTO `table`(`fname`, `lname`, `phone`, `zipcode`, `status`, `pregnant`, `month`, `day`, `year`, `ft`, `inch`, `lb`, `people`, `email`, `annual`, `recent`, `address`, `city`, `state`, `quotetype`, `unsubscribe`, `unsubscribe_type`) VALUES (
    '".$_POST['fname']."',
    '".$_POST['lname']."',
    '".$_POST['ph']."',
    '".$_POST['zip']."',
        'Accept',
    '".$_POST['gender']."',
    '".$_POST['mm']."',
    '".$_POST['dd']."',
    '".$_POST['yyyy']."',
    '5','8','80',
    '".$_POST['kids']."',
    '".$_POST['email']."',
    '".$_POST['income']."',
    '".$_POST['type']."',
    '".$_POST['address']."',
    '".$_POST['city']."',
    '".$_POST['state']."',
    'Lead','0','no')";
    $sql=mysql_query($q);
    if($sql)
    {echo "Lead Successfully submitted";}
    else
    {echo "Not Done";} 
    //Recive Data page like : get-data.php

> $handle = curl_init();

$url = "http://example.com/test.php";

包含字段名称和值的数组。

$postData = 数组(

'firstName' => '',

'姓氏' => '嘎嘎',

"提交" => "确定");

curl_setopt_array($handle,

数组(CURLOPT_URL => $url,

 // Enable the post response.
CURLOPT_POST       => true,
// The data to transfer with the response.
CURLOPT_POSTFIELDS => $postData,
CURLOPT_RETURNTRANSFER     => true, ));

$data = curl_exec($handle);

curl_close($handle);

回声$data;

$url="https://example.com/add_lead.php"; 
$postdata = "fname=".$fname."&lname=".$lname."&mm=".$mm."&dd=".$dd."&yyyy=".$yyyy."&email=".$email."&city=".$city."&state=".$state."&zip=".$zip."&address=".$address."&gender=".$lname."&ph=".$ph."&income=".$income."&type=".$type."&kids=".$kids; 
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_REFERER, $url); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec ($ch); 
echo $result;  
curl_close($ch);
发送

请求参数页面,如发送数据.php