Solved

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

Posted on 2006-11-28
4
24,600 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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