du59131 2015-10-06 00:06
浏览 16
已采纳

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

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.

  • 写回答

1条回答 默认 最新

  • dongmeng1868 2015-10-06 01:08
    关注

    "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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?