cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

RE: Posting multiple values for a single key

From: YupLounge website analyse en optimalisatie <info_at_yuplounge.com>
Date: Fri, 4 Jul 2008 09:22:15 +0200

Posting an associative array with php-curl is possible
After hours of work I once came up with the following solution:

The associative array:
$salaries["Bob"] = 2000;
$salaries["Sally"] = 4000;
$salaries["Charlie"] = 600;
$salaries["Clare"] = 0;

The only way you can send this is by serialize and urlencode. You must
urlencode it because otherwise [] are seen as new POST-fields:

And off you go.
At the receiving script you only have to unserialize.

As example Sending script:
curl_setopt ($conn, CURLOPT_POSTFIELDS ,
'salaries='.urlencode(serialize($salaries)));

Receiving script:
$salaries = unserialize($_POST['salaries']);

Even multiarray's can be send this way.

Willem

-----Oorspronkelijk bericht-----
Van: curl-and-php-bounces_at_cool.haxx.se
[mailto:curl-and-php-bounces_at_cool.haxx.se] Namens Daniel Stenberg
Verzonden: donderdag 3 juli 2008 23:52
Aan: curl with PHP
Onderwerp: RE: Posting multiple values for a single key

On Thu, 3 Jul 2008, David Yamanoha wrote:

> Alright, thanks for the feedback. I've been dreading writing my own
custom
> requests, because I honestly don't know much of anything about the http
> protocol =\

An alternative approach that might work for you is to use the curl command
line tool - simply invoked from your PHP program.

-- 
  / daniel.haxx.se
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-07-04