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.

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

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容