将数据发布到外部网站,而不仅仅是您自己的[关闭]

On PHP you have file_get_content to get the content of a page, not just your own pages, but ANYONE's page. So I'm wondering if there's a way to POST to ANYONE's website as well. So, for example. If I made an account on a forum, and want to sign in and get the content of the page, I would be able to do that remotely, by using PHP as opposing to typing in my username and password to see the website. I realize that this question may be down voted, but I just want to know if this is possible.

"Posting data to external websites, not just your own"

I just want to know if this is possible.

Yes, it's possible.

You can use the curl library for that.

Here's a small example:

$url = 'http://remotedomain.com/post.php';
$fields = array(
                'username' => "myusername",
                'password' => "mypassword"
                );

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//execute post
$result = curl_exec($ch);
//server response in now on $result

//close connection
curl_close($ch);