duanjie6912 2014-07-25 07:04
浏览 57
已采纳

PHP Curl(无重定向) - 表单提交 - 无法识别请求并返回两个变量

I am trying for a couple of days but i can not get what actually i need, i read so many posts in the internet and so many experiments but still can not get my result.

What i need:

I have server 1 and server 2. I need that i will post data from server 2 to server 1 to fill up the form and submit it without redirecting the user to server 1, and after the form is submitted i need that the PHP from server 1 will be executed and send back to server 2 the result of submitting form.

Maybe will be more clear with the code below:

By the way, the form are in ajax.

PHP from server 2:

$url_base

 = 'the_path_of_the url_of_the_form_frontend_file_server_1.php';
        $url_param =
            'name=' . $_USER['name'] .
            '&email=' . $_USER['email'] .
            '&phone=' . $_USER['phone'] .
            '&country=' . $_USER['country'].
            '&password=' . $_USER['password'] .
            '&verify_code=' . '-' .
            '&group=' . 1 .
            '&leverage=' . 100 .
            '&deposit=' . 10000 .
            '&state=' . '-' .
            '&zipcode=' . '-' .
            '&city=' . '-' .
            '&phone_password=' . '-' .
            '&send_reports=' . '-' .
            '&register_demo=' . 'yes_register';

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url_base);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $url_param);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json',
                'Content-Length: ' . strlen($url_param))
        );
        $result = curl_exec($ch);
        curl_close($ch);

My code is sending data from server 2 to server 1 and completing the form and the $result is displaying the html of the form, but i need that after the form is submitted from server 2 to server 1, i need that the php of the form from server 1 will be executed and send back the result of the form, actually after the form is submitted the result will be a login and a password for the user, the login and password is created after the form is submitted.

I am sending an extra parameter this one '&register_demo=' . 'yes_register'; to identify when the form is completed from server 1, my form have 2 files one file for front-end and another one for the back-end because i use ajax.

If i do not make a mistake seems after the form is submitted from server 2 to server 1 i get result OK but seems the php is not executed on the server 1 that i can retrieve back the login and password. And i try to GET this parameter '&register_demo=' . 'yes_register'; is doing nothing, seems that form is only submitted and not going to the back-end file.

Please i will appreciate a lot for any help, this situation is getting me crazy.

I came out with this solution because the form can be submitted only from one IP, and because of this i have the same form on another server, i need somehow to submit the form from server 2 and get the login and password to the server 2 to display it to the user.

Thanking you in advance.

  • 写回答

1条回答 默认 最新

  • douzhao1912 2014-08-01 08:04
    关注

    I will describe the solution below, and if someone need help i can help to sort it out.

    Solution:

    Because of my form is using AJAX, i was sending curl from server 2 to server 1 to complete the form and get the result after the PHP will be executed on server 1. Because of AJAX my PHP was not executed.

    So i created an API that server 2 will consume it. I implemented the form in a different file and all the PHP that i need to be executed (plane PHP). After that i was sending the CURL to that API i did and PHP start to be executed and returning the desired result.

    If someone need more help about this, please contact me and i can help, or i can put sample of code based on your request.

    Thanks guys for the correct hints.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 机器学习教材中的例题询问
  • ¥15 求.net core 几款免费的pdf编辑器
  • ¥15 C# P/Invoke的效率问题
  • ¥20 thinkphp适配人大金仓问题
  • ¥20 Oracle替换.dbf文件后无法连接,如何解决?(相关搜索:数据库|死循环)
  • ¥15 数据库数据成问号了,前台查询正常,数据库查询是?号
  • ¥15 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)
  • ¥15 彩灯控制电路,会的加我QQ1482956179
  • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
  • ¥15 (关键词-电路设计)