Solved

<? header('Content-type: text/xml'); ?> is being passed to client

Posted on 2006-11-28
4
24,529 Views
Last Modified: 2008-01-09
Ladies and Gentlemen,

I am new to web development and having a few issues.

Let’s start with the page source from within a browser:
http://img168.imageshack.us/img168/2136/11uq0.jpg

What I'm trying to do is get my RSS feed to work by pulling data from an SQL database.

So in the root dir where dance.php is I have created my .htaccess with "AddType application/x-httpd-php .xml"
Evidence: http://img241.imageshack.us/img241/593/12az1.jpg

Therefore telling my web server to treat .xml documents as php initially.

So let’s look at the source code in dreamweaver: http://img139.imageshack.us/img139/9582/13ic8.jpg

As you can see by comparing the source from the client to the source from dreamweaver that the PHP is being executed before it's passed to the browser.

APART from the header request, which gets passed.

Here is the actual page in question: http://dev.gardsys.co.uk/dance.php

If you run this page through a feed validator http://feedvalidator.org/check.cgi?url=http%3A%2F%2Fdev.gardsys.co.uk%2Fdance.php

As you can see it's 'seeing' my header change request and it's saying "Feeds should not be served with the "text/html" media type" - but if my header change request would have worked everything would be good.

Now that apache server above is one I've setup, but uploading all my content to a hosted apache server http://www.exclusivefit.com/code_cracking/dance.php it all works fine.

Now the data is exactly the same, so it must be a backed apache or php configuration problem, this is where I need your help!

Cheers
Parto

0
Comment
Question by:Rick111
  • 3
4 Comments
 
LVL 13

Accepted Solution

by:
rhickmott earned 500 total points
ID: 18026867
If I execute dance.php from your server at the top of the source code im getting.

<? header('Content-type: text/xml'); ?>

at the top of it. Its not being parsed because its not treating it as a PHP command and treating it as part of the output. As the default in PHP is HTML it will output HTML tags as its not receiving any  request otherwise.

Change your PHP code to.

<?php
     
          require_once('Connections/Gardner_SQL.php');
          header('Content-type: text/xml');
         
          // REST OF PHP HERE    
     
?>

The Header Command is a PHP FUNCTION and not a HTML request to the browser/ parser so should not be sent as part of the source code.

UNLESS you have short tags turned on in PHP.INI then

<? header('Content-type: text/xml'); ?>

Is not a valid PHP request so the browser is sending HTML headers and outputting that as plain text.

0
 
LVL 13

Expert Comment

by:rhickmott
ID: 18026884

For verification goto http://web-sniffer.net/ and enter your URL.

HTTP Response Header
Name      Value      Delim
HTTP Status Code: HTTP/1.1 200 OK
Date:      Tue, 28 Nov 2006 11:28:53 GMT      CRLF
Server:      Apache/2.2.3 (Win32) PHP/5.2.0      CRLF
X-Powered-By:      PHP/5.2.0      CRLF
Content-Length:      5032      CRLF
Connection:      close      CRLF
Content-Type:      text/html      CRLF

As you can see were are recieving a Content-Type: of text/html which is incorrect and

<? header('Content-type: text/xml'); ?>
<rss version="2.0">
<channel>
<title>Code Cracking</title>
<description>

Which is basically your PHP header command as part of the output its not executing it because it needs to be <?php header('Content-type: text/xml'); ?> in order for PHP to treat it as PHP.

Compare this with a Valid RSS feed ( http://usertools.plus.net/status/status.xml )

HTTP Status Code: HTTP/1.1 200 OK  
Date: Tue, 28 Nov 2006 11:33:17 GMT CRLF
Server: Apache/2.0.52 (Debian GNU/Linux) PHP/4.3.10-13 CRLF
Last-Modified: Tue, 28 Nov 2006 10:00:06 GMT CRLF
ETag: "44ab4f-60a8-b6f6f580" CRLF
Accept-Ranges: bytes CRLF
Content-Length: 24744 CRLF
Connection: close CRLF
Content-Type: application/xml CRLF

You will see the type is application/xml.

If your header command is not working properly first time round try

<?php header('Content-type: application/xml'); ?>
0
 
LVL 3

Author Comment

by:Rick111
ID: 18027065
thank you a lot

You're answer and explanation are nothing short of genius. Appreciate your time spent on this.

Problem solved
Thanks

Parto111
0
 
LVL 13

Expert Comment

by:rhickmott
ID: 18027074
No problem apologies for the double answer my internet connection is screwing around and I answered twice.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Maintain Parameters on URL throughout Site (PHP) 6 32
How to set default webapp for host 6 45
Google Crawl Errors Producing 404 Errors 4 78
ports for sccm 2012 1 74
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now