在php中使用curl完成自动化作业


Doing automated jobs using curl in php

我一直在寻找在外部网站上做自动化工作。我被告知我应该使用卷曲,所以我想我是在问卷曲是否是一个选择?我该如何处理这些输入字段呢

name="fname"
name="lname"
name="bio"
name="website"
name="email"
name="password"
name="Cpassword"
name="token"
name="submit"

在一个cron作业的例子中,你得到了正确的curl设置。

//The data
$data = array(
    "fname" => "Mark",
    "lname" => "Jones",
    "Bio" => "Hi i like rose's because they smell nice",
    "website" => "http://mysite.com",
    "email" => "mark@mysite.com",
    "password" => "mypassword",
    "token" => "your token",
    "Agent" => "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5"
);
//External site direct link
$external_site = "http://external-site.com";
//Input field names with data ready
$input_fields = "fname=".$data['fname']."&lname=".$data['lname']."&Bio=".$data['bio']."&website=".$data['website']."&email=".$data['email']."&password=".$data['password']."&Cpassword=".$data['password']."&token=".$data['token']."&submit=";
//Do the curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL , $external_site);
curl_setopt($ch, CURLOPT_USERAGENT, $data['Agent']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $input_fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$done = curl_exec ($ch);
curl_close($ch);

有关curl的更多信息,请访问http://php.net/manual/en/book.curl.php,对于cron作业,大多数主机提供了一个现成的cron特性来使用XD。