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:


 = '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);

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.

2014/07/25 07:04
  • request
  • curl
  • php
  • 点赞
  • 收藏
  • 回答