Search code examples
phpcurljobs

Doing automated jobs using curl in php


I have been looking to do automated jobs on an external site. I have been told that I should be using curl, so I guess I am asking if curl is an option? And how would I go about doing that with these input fields:

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

Solution

  • Yes you have been told correctly using curl set on a cron job example.

    //The data
    $data = array(
        "fname" => "Mark",
        "lname" => "Jones",
        "Bio" => "Hi i like rose's because they smell nice",
        "website" => "http://mysite.com",
        "email" => "[email protected]",
        "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);
    

    For more info on curl visit http://php.net/manual/en/book.curl.php and for cron job's most host's provide a ready cron feature to use XD.