Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
182 views
in Technique[技术] by (71.8m points)

php - pull data from csv file and submit each row to url with curl

I am looking for guidance on the following code. I have numerous large CSV files that are in the format of

firstname,lastname,address,state,zip,email,homephone,dob,optindate,ipaddress,url
Joey,Demo,4004 S. Louise Ave. 206,Sioux Falls,SD,57106,jdemo@hotmail.com,6053231657,06/18/1944,4/19/2008 11:58:34,12.174.252.216,http://www.ecoupons.com

I am trying to add a few new variables, convert the data to a http_build_query and submit each row to a url with POST.

Here is my code

$processid = '123454r4rt5rt5rtr';
$version = '1.0.0';
$partnercode = 'ABC';
$listid = 'ID12345';

$fp= fopen("test.csv", "r");

while (!feof($fp) ) {
     list($firstname,$lastname,$address,$city,$state,$zip,$email,$phone,$dob,$optindate,$ipaddress,$url) = fgetcsv($fp);
$data = array('firstname' => $firstname,
'lastname' => $lastname,
'address' => $address,

'city' => $city,
'state' => $state,
'zip' => $zip,
'email' => $email,
'homephone' => $phone,
'dob' => $dob,
'optindate' => $optindate,
'ipaddress' => $ipaddress,

    'url' => $url,
    'processid' => $partnercode,
    'version' => $version,
    'partnercode' => $partnercode,
    'listid' => $listid);

    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://localhost.com');
    curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt(CURLOPT_USERPWD, 'usernameassword')

$data = curl_exec($ch);

curl_close($ch);

When I am testing right now I keep getting unexpected T_VARIABLE but I am not 100% sure my coding is correct.

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

curl_setopt(CURLOPT_USERPWD, 'usernameassword') should be curl_setopt(CURLOPT_USERPWD, 'usernameassword'); with semi-colon at the end.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...