在一个服务器上提交表单,进行处理,然后将结果发布到另一个域 [英] Submit form on one server, process it and then post results to another domain

查看:77
本文介绍了在一个服务器上提交表单,进行处理,然后将结果发布到另一个域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一页上有一个表单,其操作设置为/process.php

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

在process.php中,我对表单进行了验证,并且还将其写入位于其上的服务器上的数据库中.

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

将变量写入数据库后,我想做的就是将变量发布到另一个域,该域将以不同的方式处理这些变量.

What I'd like to do after it has written to the database, is post the variables to another domain that will then process those variables differently.

推荐答案

您可以将file_get_contents用于相同的内容.

you can use file_get_contents for the same.

示例:

$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;

这篇关于在一个服务器上提交表单,进行处理,然后将结果发布到另一个域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆