I am trying to post to another server without a form. The input is from a
form on my server. I log the entry in MySQL and then pass the input to this
function to open the connection and return a query result.

The post to the other server requires authentication in the form of USERID
and PASSWORD. At first this function returned "HTTP 1.1/ Authentication
Required" and now it is timing out.

Incidentally, I have posted this data directly from a form with no problems.
Anyone know why this isn't working?


function process_CRIS($USERID, $PASSWORD, $S_S, $S_M, $SRCH__LNAME,
$SRCH__FNAME)
{
        $url = "http://10.0.0.10/premium/comb/Results.phtml";;
        $url = preg_replace("@^http://@i";, "", $url);
        $host = substr($url, 0, strpos($url, "/"));
        $uri = strstr($url, "/");
        $UserID = "xxxx";
        $Password = "xxxxx";
        $reqbody="USERID=".urlencode($UserID);
        $reqbody=$reqbody."&PASSWORD=".urlencode($Password);
        $reqbody = $reqbody."&S_S=".urlencode($S_S);

        // $S_S can consist of an array of possible search parameters that need to
be concatenated to ab,ac,ad, etc.
        if (isset($S_S)){
                foreach($S_S as $key=>$val)
                {
                        if ($key == 0){ $reqbody = $reqbody."&S_S=".urlencode($val);}
                        else
                        {$reqbody = $reqbody.",".urlencode($val);}
                }
                }

        if (isset($S_M)){
                foreach($S_M as $key=>$val)
                {
                        if ($key == 0){$reqbody = $reqbody."&S_M=".urlencode($val);}
                        else
                        {$reqbody = $reqbody.",".urlencode($val);}
                }
                }

        $reqbody = $reqbody
."&SRCH__LNAME=".urlencode($SRCH__LNAME)."&SRCH__FNAME=".
        urlencode($SRCH__FNAME);


        $contentlength = strlen($reqbody);
        $reqheader =  "POST $uri HTTP/1.1\r\n".
                   "Host: $host\n".
        "Content-Type: application/x-www-form-urlencoded\r\n".
         "Content-Length: $contentlength\r\n".
        "$reqbody\r\n";

         $socket = fsockopen($host, 80, $errno, $errstr);

if (!$socket) {
   $result = "Error: ".$errno. $errstr;
   return $result;
   exit;
}

        fputs($socket, $reqheader);


         $result = fgets($socket, 4096);

fclose($socket);
return $result;

}


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to