1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| // Pour assurer la compatibilité avec les versions PHP 4
if (!function_exists('http_build_query')) {
function http_build_query($formdata, $numeric_prefix = NULL, $arg_separator = '', $parent_key = '') {
$ret = array();
if (is_array($formdata)) {
if (empty($arg_separator)) {
$arg_separator = ini_get('arg_separator.output');
}
foreach ($formdata as $k => $v) {
if (is_int($k) && $numeric_prefix != NULL) {
$k = $numeric_prefix . $k;
}
if ($parent_key != '') {
$k = sprintf('%s[%s]', $parent_key, $k);
}
if (is_array($v)) {
array_push($ret, http_build_query($v, NULL, $arg_separator, $k));
} elseif (is_object($v)) {
array_push($ret, http_build_query(get_object_vars($v), NULL, $arg_separator, $k));
} else {
array_push($ret, urlencode($k) . '=' . urlencode($v));
}
}
}
return implode($arg_separator, $ret);
}
}
// Faire suivre les données POST à une autre page
$ch = curl_init('https://site-distant.fr/');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_POST));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$ret = curl_exec($ch);
if (!$ret) {
echo curl_error($ch);
} else {
echo $ret;
}
curl_close($ch);
} |
Partager