<?php // $remotehost: l'host sul quale risiede il CGI remoto // $remotepath: il path del CGI remoto da utilizzare // $remotemethod: il metodo per chiamare il CGI remoto $data = ""; // azzera la variabile $QUERY_STRING = $_SERVER["QUERY_STRING"]; foreach ($_REQUEST as $key => $value){ eval("\$$key = \"$value\";"); } $fields = explode("&", $QUERY_STRING);// e' necessario che questo script sia chiamato con metodo GET foreach ($fields as $field) { // ciclo su tutti i campi per eliminare ... $var = explode("=", $field); if ($var[0] != "remotehost" && // remote-host $var[0] != "remotepath" && // remote-path $var[0] != "remotemethod") { // remote-method if ($data == "") { // ricostruisco la QUERY_STRING da passare alla funzione $data = $field; } else { $data = $data."&".$field; } } } sendToHost($remotehost,$remotemethod,$remotepath,$data); /* sendToHost * ~~~~~~~~~~ * Params: * $host - Just the hostname. No http:// or /path/to/file.html portions * $method - get or post, case-insensitive * $path - The /path/to/file.html part * $data - The query string, without initial question mark * * Examples: * sendToHost('www.google.com','get','/search','q=php_imlib'); * sendToHost('www.example.com','post','/some_script.cgi', * 'param=First+Param&second=Second+param'); */ function sendToHost($host,$method,$path,$data) { // Supply a default method of GET if the one passed was empty if (empty($method)) $method = 'GET'; $method = strtoupper($method); $ch = curl_init(); if ($method == 'GET') { $URL="$host$path?$data"; curl_setopt($ch, CURLOPT_URL,"http://$URL"); curl_setopt($ch, CURLOPT_POST, 0); } else { $URL="$host$path"; curl_setopt($ch, CURLOPT_URL,"http://$URL"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } curl_setopt($ch, CURLOPT_HTTP_VERSION,"1.0"); curl_exec ($ch); curl_close ($ch); } ?>