【问题标题】:Sending Data over another website via PHP通过 PHP 通过另一个网站发送数据
【发布时间】:2013-11-03 12:53:50
【问题描述】:

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

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

我在那里找到了部分答案: Creating a 'robot' to fill form with some pages in

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

【问题讨论】:

  • 查看 PHP 的 curl 扩展。或者,使用 Requests for PHP 之类的库让您的生活更轻松
  • 是的,您可以使用 CURL 来模拟任何 HTTP 请求,它还会为您跟踪 cookie。 CURL PHP 库只是curl.haxx.se 的包装器。

标签: php


【解决方案1】:

$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;

【讨论】:

    【解决方案2】:
    $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
    

    【讨论】:

    • 你确定你把这个答案发布到了正确的问题上吗?
    • 是的,这是这个问题的完整答案。因为我在过去 2 天找到了答案。但仍然没有得到完整的答案。之后我找到了解决方案并发布了完整的答案
    【解决方案3】:
    $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);
    

    //发送请求参数页面如send-data.php

    【讨论】:

      【解决方案4】:

      你可以试试SimpleTest,但通常服务会提供一个API接口来与它们交互。

      【讨论】:

        【解决方案5】:

        答案的另一部分就在这里。您可以通过 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);
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-02-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-12-07
          相关资源
          最近更新 更多