send cURL post to be received exactly like form post

Discussion in 'PHP' started by tableman, Aug 14, 2010.

  1. #1
    Is it possible to send a few simple form entries using PHP in a separate file so that a remote server receives the data in the exact same way as if sent directly from the form? Here is the situation:

    Users make entries into a form on my site which are then sent to a remote server which generates a variable length page of results for the users' perusal. I want the results to be displayed on my site but I discover that there is a problem with iframe height so I am trying PHP in a separate file to avoid an iframe. Then maybe I can cache the result pages and display them without needing an iframe. The Javascript remote server security issue looks daunting so I am trying to use a PHP solution first.

    The following PHP code generates a "... no wrapper... " error and is apparently because fopen and fsockopen etc. are set to "off", for security reasons, by the host that I use:
    
    $url="http://remote_server.cgi";
    foreach($_POST as $key => $value)
    {$url .="$key=" . urlencode($value) . "&";}
    $array = file($url);]
    
    PHP:
    The host runs PHP version 4.3.11 and has cURL enabled so I try that but the form entries are not being accepted as they are with a post direct from the form:
    
    $URL="http://remote_server.cgi";
    $postfields=array();        //FOR urlencode and querystring expected by CURL_POSTFIELDS. 
    foreach($_POST as $key=>$val) $postfields[]="$key=".urlencode($val);
    $postfields = join("&", $postfields);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $URL); 
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
    curl_exec ($ch);    
    curl_close ($ch);
    
    PHP:
    In case useragent recognition was a security issue at the remote server, I added:
    
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
    
    PHP:
    I know all entries are received by using:
    
    print_r($_POST);
    
    PHP:
    But the remote server still says "Error in form found. You are not authorized... etc. etc... "

    The remote server must be receiving the entries differently from how it gets them directly from the form.

    What could the issues be and what fixes can I try?
     
    tableman, Aug 14, 2010 IP