Saturday, 2 August 2014

Generated XML with PHP can't render in LINUX



I define multiple XML file for my website sitemap. One of them generated dynamically.

This file correctly render on windows (My OS :( ) and also on windows server (local server OS) as below:



<urlset xmlns="http://ift.tt/xwbjRF">
<url>
<loc>http://ift.tt/1rWv0gC;
<lastmod>2014-08-02</lastmod>
<changefreq>hourly</changefreq>
<priority>0.7</priority>
</url>

<url>
<loc>http://ift.tt/1rZaH5G;
<lastmod>2014-08-02</lastmod>
<changefreq>hourly</changefreq>
<priority>0.7</priority>
</url>
...
...


But when I upload my codes on Linux server(centOS), this page is just blank white page.

My PHP code to generate this XML is:



<?php
header('Content-type: application/xml');
if(isset($_GET['type']))
$type = $_GET['type'];
else
$type = 'category';
require_once '/protected/PDODB.php';
// configuration
switch ($type)
{
case 'category':
$sql = 'SELECT id,ename FROM tbl_category WHERE status=0';
$priority = 0.7;
$changefreq = 'hourly';
break;
case 'group':
$sql = 'SELECT gr.id groupId, gr.ename groupName, cat.id catId, cat.ename catName '.'FROM tbl_group gr, tbl_category cat WHERE gr.status=0';
$priority = 0.6;
$changefreq = 'hourly';
break;
case 'object':
$sql = 'SELECT name,code,time FROM tbl_object WHERE status=0';
$priority = 0.5;
$changefreq = 'daily';
break;
default:
$sql = 'SELECT id,ename FROM tbl_category WHERE status=0';
$priority = 0.7;
$changefreq = 'hourly';
break;
}

?>
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://ift.tt/xwbjRF">
<?PHP foreach ($dbh->query($sql) as $row): ?>
<url>
<loc>
<?PHP if($type == 'category'): ?>
http://ift.tt/1rWuXBt echo $row['ename']; ?>/CTG-<?PHP echo $row['id']; ?>
<?PHP elseif($type == 'group'): ?>
http://ift.tt/1rWuXBt echo $row['catName']; ?>/<?PHP echo $row['groupName']; ?>/<?PHP echo $row['catId']; ?>-<?PHP echo $row['groupId']; ?>
<?PHP elseif($type == 'object'): ?>
http://ift.tt/1rZaH5I echo $row['code']; ?>
<?PHP endif; ?>
</loc>
<lastmod>
<?PHP if($type == 'object'): ?>
<?PHP echo date('Y-m-d', $row['time']); ?>
<?PHP else: ?>
<?PHP echo date('Y-m-d', time()); ?>
<?PHP endif; ?>
</lastmod>
<changefreq><?PHP echo $changefreq; ?></changefreq>
<priority><?PHP echo $priority; ?></priority>
</url>
<?PHP endforeach; ?>
</urlset>


Could you please tell me where is the problem?

Any help will be appreciated.


No comments:

Post a Comment