PHP将数据发送到其他网页

I want to have a script on one website and database on other website.

First website has 2 fields where they enter username and password. Then php posts username/password to other php file and that php does something and then somehow sends the data to my second website, where I insert username and password to MySql database.

So I can do everything except:

I have 2 variables in PHP file, and I want to send them to other webpage, which gets them with maybe $_POST ? Also posting should be automatic, so the script posts them itself not via button press. How to do it?

Is my question clear? I can explain.

Thanks.

Why can't your script on your dummy website retrieve the data via $_POST and then call the script from your real website?

http://davidwalsh.name/execute-http-post-php-curl

Check that out. This way your can POST to your real website from your dummy site's script, completely transparent to the user.

Hope that makes sense.

There are three obvious ways to do this:

1) Simple – keep the page hosted on site 2, but use an iframe on site 1 to embed it.

2) Post the form from site 1 to site 2 by setting the action attribute to a script on site 2.

3) Post the form on site 1 to a script on site 1, then use CURL to post it to the other site behind the scenes.

You can use the PHP cURL library to send these kinds of data requests.

Link: http://php.net/manual/en/book.curl.php

 /**
 * create request || application/json
 * @param $method
 * @param $url
 * @param $args
 * @param $isSentBody
 * @param $cert
 * @return resource
 */

function createRequest($method, $url, $args, $isSentBody, $cert = false)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    if ($method == 'POST')
        curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($args));

    if ($isSentBody) {
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($args));
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            //'Authorization : Bearer ' . getAccessToken(),
        ));
    }
    if ($cert)
        curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . $cert);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    try {
        return curl_exec($ch);
    } catch (Exception $e) {
        throw $e;
    }
}