将数据发布到外部网站,而不仅仅是您自己的[关闭](Posting data to external websites, not just your own [closed])

编程入门 行业动态 更新时间:2024-10-28 05:21:52
将数据发布到外部网站,而不仅仅是您自己的[关闭](Posting data to external websites, not just your own [closed])

在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);

更多推荐

本文发布于:2023-07-15 22:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1119404.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自己的   而不   仅仅是   数据   网站

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!