doujiao2443 2016-03-03 12:55
浏览 58
已采纳

在CodeIgniter模型中包含文件会导致服务器将脚本转储到网页上

I'm trying to develop an application on code igniter framework. My question is when I wrote the model of my application it grew large, so I broke it down into two separate file. The main files merely calls the other one using include command. The problem is that the calling file dumps the script in the called file in plain text on the web browser. enter image description here

my model file looks like this :

<?php
defined('BASEPATH') or exit('No direct script access allowed');

    class Admin_model extends CI_Model{
        public function __construct(){
            parent::__construct();
            $this->load->database();
        }
    public function return_admin_dashboard_articles($priviledge_id,$by_author=null,$date_published=null){
                $index = 0;
                $query_articles = null;
                //fetching list of articles
                include 'includes/posts_query.inc.php';
                return $data;
    }
    }
    ?>

and the file posts_query.inc.php looks like this:

<?php>
if($priviledge_id==1 || $priviledge_id==2){

    $this->db->select('articles.id,articles.title,articles.summary,users.user_name,date(articles.pub_date) as 
    pubs_date,articles.author');//add date and time stamp to the table

    $this->db->from('articles');

    $this->db->join('users','articles.author=users.user_id');

    if($by_author and $date_published==null){


        $this->db->where('articles.author',$by_author);

    }

    else if($by_author=='all' and $date_published){

        $this->db->where('date(articles.pub_date)=',$date_published);

    }
    $this->db->where('users.user_priviledge_id=',$priviledge_id); //change this to user_priviledge_id>$priviledge_id to see articles by all the users
    $query_articles = $this->db->get();
}
            //echo $query_articles;
else{
    $this->db->select('articles.id,articles.title,articles.summary,users.user_name,date(articles.pub_date) as pubs_date,articles.author');//add date and time stamp to the table:done
    $this->db->from('articles');
    $this->db->join('users','articles.author=users.user_id');
    $this->db->where('users.user_priviledge_id=',$priviledge_id);
    $query_articles = $this->db->get();
}

if($query_articles->num_rows()>0){
    foreach($query_articles->result_array() as $row){
        $data['articles'][$index]=array(
            'id'=>$row['id'],
            'title'=>$row['title'],
            'summary'=>$row['summary'],
            'author'=>$row['user_name'],
            'date'=>$row['pubs_date'],
            'author_id'=>$row['author']
                        //'time'=>$row['time']
        );
        $index++;
    }     
}
else{
    $data['error']['articles']='Could not fetch articles';
}
?>            

The complete posts_query.inc.php file is displayed on the web page. What is the reason behind this? Any help will be much appreciated.

Thanks.

I'm running XAMPP (Apache 2.4.10, PHP 5.6.3,MySql 5.6 CodeIgniter 3.0) on windows 10.

  • 写回答

1条回答 默认 最新

  • duanmiaosi0150 2016-03-03 13:57
    关注

    The posts_query.inc.php file begins with <?php>.
    It should be <?php. The > is causing the problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料