Submit form on one server, process it and then post results to another domain

后端 未结 2 1875
你的背包
你的背包 2021-01-15 20:25

I have a form on one page with the action set to /process.php

Within the process.php I have the validation of the form and also it writes to a database on the server

2条回答
  •  星月不相逢
    2021-01-15 21:05

    you can use file_get_contents for the same.

    Example:

    $name="foobar";
    $messge="blabla";
    
    $postdata = http_build_query(
        array(
            'name' => $name,
            'message' => $message
        )
    );
    
    $opts = array('http' =>
        array(
            'method'  => 'POST',
            'header'  => 'Content-type: application/x-www-form-urlencoded',
            'content' => $postdata
        )
    );
    
    $context  = stream_context_create($opts);
    
    $result = @file_get_contents('http://yourdomain.com/process_request.php', false, $context);
    
     if($http_response_header[0]=="HTTP/1.1 404 Not Found"):
    
                echo "iam 404";
    
     elseif($http_response_header[0]=="HTTP/1.1 200 OK"):
    
                echo "iam 200";
    
     else:
    
                echo "unknown error"; 
    
     endif;
    

提交回复
热议问题