在PHP上你有file_get_content来获取页面的内容,而不仅仅是你自己的页面,而是任何人的页面。 所以我想知道是否有办法向任何人的网站发帖。 所以,例如。 如果我在一个论坛上创建了一个帐户,并希望登录并获取该页面的内容,我可以远程执行此操作,使用PHP反对输入我的用户名和密码来查看该网站。 我意识到这个问题可能会被投票,但我只是想知道这是否可行。
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.
最满意答案
“将数据发布到外部网站,而不仅仅是您自己的网站”
我只是想知道这是否可行。
是的 ,这是可能的。
您可以使用curl库 。
这是一个小例子:
$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);"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);更多推荐
发布评论