Codeigniter 点击一个 url 并返回

标签 codeigniter

我在我的网络应用程序中使用 codeigniter 3.0。我想点击一个 URL 然后返回到一个 View 。假设点击一个按钮,我想点击一个 API,然后返回到带有成功消息的同一 View 。有人可以帮忙吗?

我的API是http://wmlab.in/api/getData.php?username=web

我尝试了 file(' http://wmlab.in/api/getData.php?username=web ') 但它不起作用。

最佳答案

使用curl来做到这一点,如果您的服务器没有curl,也可以安装curl。

     url="http://wmlab.in/api/getData.php?username=web";


     function getUrlContent($url){
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);

          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
          curl_setopt($ch, CURLOPT_TIMEOUT, 5);
          $data = curl_exec($ch);
          echo $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
          curl_close($ch);
          return ($httpcode>=200 && $httpcode<300) ? $data : false;
        }
       $content=getUrlContent($url);
        echo $content;

关于Codeigniter 点击一个 url 并返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31666794/

相关文章:

php - 如何在 codeigniter 中发送多个具有相同名称属性的选择框值

php - 在 PHP 中打印最后执行的 Mysql 查询

php - 无法加载请求的类 : session

php - MySql 事务

php - 在Codeigniter中的同一个mysql表中上传图像和文本

codeigniter - CodeIgniter事件记录不在字符串中

php - 想要用codeigniter连接sql数据库

mysql - 如何使用条件日期现在显示来自mysql的数据

php - codeigniter 以及在 where(array) 函数中使用多索引

php - Codeigniter:从单列中获取所有值作为数组