Part of the EllisLab Network
   
 
Source Code occasionally getting displayed in the browser
Posted: 28 December 2009 01:46 PM   [ Ignore ]  
Summer Student
Total Posts:  2
Joined  09-23-2009

Hi Everyone -

Noticed kind of a weird behavior of CI, that it displays portion of the source code once in a while. Mostly when there is a label it tend to display the source code around it. It’s very random and mostly the source code display goes off once you refresh the page again.

The annoying part is that it keep displaying the source code once in a while consistently. Also, I’ve noticed this when using Google Chrome.

Is that a bug in CI? Or is it something that I’m missing?

Please let me know.

Thanks in advance.

Profile
 
 
Posted: 28 December 2009 03:23 PM   [ Ignore ]   [ # 1 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1235
Joined  05-17-2009

You should share some code so we can see what you are doing wrong.

 Signature 

Brian
Brian’s Web Design - Temecula
Community Auth - CodeIgniter Authentication Application

Profile
 
 
Posted: 13 July 2010 11:07 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  22
Joined  05-19-2007

I’m having the exact same issue - seemingly random html source code is getting displayed in Chrome at random moments. When you refresh the page it’s displayed normally. Other browsers don’t have this issue.
It only happens with my CI installations.

Basically every view is affected and there isn’t really anything ‘special’ about any of them.
I’ll post some examples anyway:

<td valign='top' width='80%'><?=$event->description?></td

the $event->description var sometimes contains an html-tag, like “”, which just gets displayed in the browser instead of being parsed for some reason.
The only thing ‘special’ about this code that I see here is that I’m using short-tags, but these are being handled by PHP, and I have $config[‘rewrite_short_tags’] set to FALSE in my config.php so there should be no conflict either.
Sometimes it also happens with code that isn’t echoing a variable, like here:

<td><?=anchor('guestbook/manage''Guestbook beheren')?></td

- which sometimes displays in the browser as ” onium/guestbook/manage”>Guestbook beheren” which weirdly links to “http://localhost/panddem<script type=”. You see what’s happening…

Also, *all* of my CI projects suffer from this - both the live versions (most of them hosted on One.com) and also my localhost ones.


Any ideas?

Profile
 
 
Posted: 13 July 2010 12:23 PM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1835
Joined  12-08-2009

Sounds like an extension gone awry.

 Signature 

@basdflasjk | BitAuth: Authentication and Role-based Permissions | Session Library Replacement


Please read the User Guide! (Upgrading from a previous version?)

Profile
 
 
Posted: 14 July 2010 03:19 AM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  22
Joined  05-19-2007

Any idea where I should start looking…? I’ve been having this issue for a while now.

Profile
 
 
Posted: 14 July 2010 03:33 AM   [ Ignore ]   [ # 5 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1235
Joined  05-17-2009
stijnvdb - 14 July 2010 07:19 AM

Any idea where I should start looking…? I’ve been having this issue for a while now.

Probably in the controller, model, library, or view that is generating the error. I asked you earlier to post some code. It will be nearly impossible to help you unless you do so.

 Signature 

Brian
Brian’s Web Design - Temecula
Community Auth - CodeIgniter Authentication Application

Profile
 
 
Posted: 14 July 2010 03:56 AM   [ Ignore ]   [ # 6 ]  
Summer Student
Total Posts:  22
Joined  05-19-2007

That was a different poster mate! smile
Regardless, I already posted some code of views that have the issue (see a couple posts earlier) -  and here’s the controller and model code for the first one (the one where the variables - fetched from db - can contain html-tags like

<p

, which are for some reason displayed in the browser instead of being parsed):

Controller:

function Event()
    
{
        parent
::Controller();    
        
$this->load->helper('typography');
        
$this->load->helper('form');
        
$this->load->library('validation');
        
$this->load->model('eventmodel');
        
$this->load->model('bandmodel');
        
$this->data['title'"Events";
    
}

    
function getUpcoming($count 0)
    
{
        $data[
'upcoming'$this->eventmodel->getUpcoming($count);
        if(
$data['upcoming']->num_rows() > 0)
        
{
            $this
->data['main'$this->load->view('event/upcoming'$dataTRUE);
        
}
        
else
        
{
            $data[
'upcoming'$this->eventmodel->getPast($count);
            
$this->data['main'"<h3>Afgelopen evenementen:</h3>";
            
$this->data['main'.= $this->load->view('event/upcoming'$dataTRUE);
        
}
        $this
->load->view('layout/layout'$this->data);
    
}
    
    
function index()
    
{
        
return $this->getUpcoming(10);
    

Model:

function Eventmodel()
    
{
        parent
::Model();
    
}
    

    
function getUpcoming($count 0)
    
{
//        $this->output->enable_profiler('TRUE');
        
$this->db->where('date >='date("Y-m-d"));
        
$this->db->limit($count);
        
$this->db->orderby('date');
        return 
$this->db->get('pand_events');
    
    

And here’s the second one, this is the one that has it near the <?=anchor(’...’)?> function:

Controller:

function Admin()
    
{
        parent
::Controller();    
        
$this->load->library('validation');
        
$this->load->helper('form');
    
}
    
    
function index()
    
{
        
if (! $this->session->userdata('admin_id')) { redirect('/admin/login'.$this->uri->uri_string(), 'REFRESH'); }
        
// adminpanel
        
        
$this->data['title'"Adminpanel";
        
$this->data['main'$this->load->view('admin/panel'NULLTRUE);
        
        
$this->load->view('layout/layout'$this->data);
    

(no model is used here)

However, I suspect that the code I just posted is pretty much irrelevant to my problem. As far as I know I’m not doing anything special here - I’m not using my own libraries and haven’t touched CI core either, and the problem I’m describing is happening pretty much *everywhere*. These are just two examples of pages where the problem randomly presented itself when I wanted to recreate it to show you what’s going wrong, but in reality I have this problem all over my website - which is why I think the problem is more likely to be config-related or something like that? I have a standard CI installation and pretty much a standard config as far as I can tell.

Profile
 
 
Posted: 14 July 2010 05:08 AM   [ Ignore ]   [ # 7 ]  
Grad Student
Avatar
Rank
Total Posts:  43
Joined  07-12-2010
stijnvdb - 13 July 2010 03:07 PM

I’m having the exact same issue - seemingly random html source code is getting displayed in Chrome at random moments. When you refresh the page it’s displayed normally. Other browsers don’t have this issue.

Seems to me that it could be (dare I say it!) a problem at Google’s end red face . You say the problem occurs randomly and when you refresh the page it goes away. Also that other browsers don’t have the same problem.

I would be interested to know if it is CI tho big surprise .

Profile
 
 
Posted: 14 July 2010 05:12 AM   [ Ignore ]   [ # 8 ]  
Summer Student
Total Posts:  22
Joined  05-19-2007

Yeah, it’s the combination I guess. There’s a definitely a problem at Chrome’s end since it’s behaving differently from the other browsers in this way, but also a problem with my CI installations since my regular php projects don’t have this issue.
CI + Chrome = fail? :(

Profile
 
 
Posted: 14 July 2010 05:29 AM   [ Ignore ]   [ # 9 ]  
Grad Student
Avatar
Rank
Total Posts:  43
Joined  07-12-2010

Just reading back over the last few posts and this concerns me slightly.

stijnvdb - 14 July 2010 07:56 AM

(the one where the variables - fetched from db - can contain html-tags like

<p

, which are for some reason displayed in the browser instead of being parsed):

From this sentence it says to me that you are getting raw html from a db query. Don’t want make anyone sound stupid, but are these being escaped before inserting into the db??  If not these can cause random errors when echoed back into a html file.

Profile
 
 
Posted: 14 July 2010 05:37 AM   [ Ignore ]   [ # 10 ]  
Summer Student
Total Posts:  22
Joined  05-19-2007

Well I believe they are? I just use CodeIgniter’s Active Record class, and in the userguide it reads “It also allows for safer queries, since the values are escaped automatically by the system.” - so I never really bothered checking into that myself, I hope I didn’t interpret that part horribly wrong by assuming I could pass pretty much any kind of value?

Also the problem presents itself in functions where there is no db-activity at all (example #2 doesn’t even use a model), so I don’t think it would be related if I messed up there - but obviously good to know regardless smile

Thanks for helping me out with this by the way! Appreciate it!

Profile
 
 
Posted: 14 July 2010 06:39 AM   [ Ignore ]   [ # 11 ]  
Grad Student
Avatar
Rank
Total Posts:  43
Joined  07-12-2010

When there is a problem does the source code read right. IE if you view the source code of the page, is there anything missing?

Profile
 
 
Posted: 14 July 2010 07:24 AM   [ Ignore ]   [ # 12 ]  
Summer Student
Total Posts:  22
Joined  05-19-2007

That’s the strange thing about it - the source code looks exactly the way it should - to make sure I copy/pasted the source code of a page that displayed this error (only happens sporadically, I have to navigate from and to the page a couple of times to recreate it) into a .html file, which displayed normally - as did the page that showed the error once I refreshed it.

Profile
 
 
Posted: 14 July 2010 08:55 AM   [ Ignore ]   [ # 13 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1835
Joined  12-08-2009

Server side code is executed on the server. Whether the code is written in CI, RoR, perl, VB or smoke signals is irrelevant as far as the browser is concerned. If the code you posted is to be believed, javascript is being inserted which you haven’t written. Disable all of your chrome extensions, toolbars, antivirus, etc.

 Signature 

@basdflasjk | BitAuth: Authentication and Role-based Permissions | Session Library Replacement


Please read the User Guide! (Upgrading from a previous version?)

Profile
 
 
Posted: 14 July 2010 09:15 AM   [ Ignore ]   [ # 14 ]  
Summer Student
Total Posts:  22
Joined  05-19-2007

Aka: If test this problem later on today on an otherwise completely clean computer with Google Chrome installed and default extensions loaded and still have this issue (chances of that are fairly realistic since the first poster here had the issue I do - and I don’t have any special extensions / toolbars installed on the computer I’ve been testing with) then Chrome is to blame? Either way, you have a really good point there and I’m going to test this later on today and post the results here, I’m very curious!

However, giving it some extra thought I still think it’s really weird that I’m having this issue with my CI projects but not with plain old native PHP… What would be your take on that? Something I’m doing *must* still be triggering this behavior somehow, otherwise there would be a lot more people having this issue and I’d also have it with a bunch of other websites - which I don’t.

Profile