Solved

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

Posted on 2006-11-28
4
24,517 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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
No problem apologies for the double answer my internet connection is screwing around and I answered twice.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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