1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP in XML File

Discussion in 'PHP' started by adamjblakey, Apr 23, 2014.

  1. #1
    Hi,

    I have a script below which has been working fine however i have just moved server and rather than showing the page, it now just downloads it. Any ideas? The page is called sitempa.xml and the script is below. My thoughts is that the new server does not support something but not sure what to ask them to activate.

    <?php
    // include init which contains all the includes.
    include('init.php');
    function stripres($value){
       $value = strtr($value, "éèêàëâúóíáABCDEFGHIJKLMNOPQRSTUVWXYZ. ","eeeaeauoiaabcdefghijklmnopqrstuvwxyz--");
       $value = ereg_replace('[^a-zA-Z0-9_-]', '', $value);
       return $value;
    }
    header('Content-Type: application/xml');
    echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
    ?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <?php
        $result = mysql_query("SELECT * FROM `pages` WHERE memberid = '$resv[id]' AND page_link = ''");
        while ($row = mysql_fetch_assoc($result)) {
    ?>
    <url>
    <?php
        if ($row['page_name'] == 'Home Page'){
    ?>
        <loc>http://<?php print $_SERVER['HTTP_HOST']; ?></loc>
    <?php }else{ ?>
    <loc>http://<?php print $_SERVER['HTTP_HOST']."/".$row['page_url'].".html"; ?></loc>
    <?php } ?>
        <lastmod><?php print $row['sdate']; ?></lastmod>
        <changefreq>daily</changefreq>
        <priority>0.5</priority>
    </url>
    <?php } ?>
    </urlset>
    
    Code (markup):
     
    adamjblakey, Apr 23, 2014 IP
  2. hdewantara

    hdewantara Active Member

    Messages:
    302
    Likes Received:
    10
    Best Answers:
    9
    Trophy Points:
    68
    #2
    I might have the same situation last year with .webm files (HTML5 videos); any browsers had refused to stream them and offered instead popups for downloading. What I did to resolve it is by entering server Control-Panel and go for MIME-Type thumb/ icon. There I saw that this kind / type of file hasn't been registered. I just add this type and voila... no more popups.

    So maybe you should see your Control-Panel > Mime-Type page too, and check whether "application/xml" hasn't been enlisted there.

    Hendra
     
    hdewantara, Apr 23, 2014 IP
  3. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    624
    Likes Received:
    32
    Best Answers:
    20
    Trophy Points:
    100
    #3
    Replace:

    
    header('Content-Type: application/xml');
    
    Code (markup):
    With:

    
    error_reporting(-1);
    ini_set('display_errors', 'on');
    
    Code (markup):
    And see if there are any errors/warnings.
     
    ThePHPMaster, Apr 23, 2014 IP
  4. tylerman169

    tylerman169 Member

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    2
    Trophy Points:
    43
    #4
    Can you try renaming the file to "sitemap.php" instead of "sitemap.xml"? Most place, including Google Webmaster Tools, accept both PHP and XML sitemaps. I also use a similar script on my website and the file needs to be named sitemap.php to work.

    If this does not solve the problem. Here are a few other common solutions to that type of problem:

    Make sure your httpd.conf file contains the following:
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    
    Code (markup):
    Also make sure the php module is loaded:

    LoadModule php5_module libexec/apache2/libphp5.so
    Code (markup):

    It might help if you post the contents of your httpd.conf file.
     
    tylerman169, Apr 23, 2014 IP
  5. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #5
    Many thanks for your replies, the last reply worked great :)
     
    adamjblakey, Apr 28, 2014 IP