首页 > 解决方案 > Rss 提要未在浏览器中显示为提要

问题描述

<?php
  include 'classes/db.connect.php';
  if (isset($_GET['user'])) {
    if($blog->blog_check($_GET['user'])) {
      $username = strip_tags($_GET['user']);
    } else {
      http_response_code(404); include('html/blogs/404.html'); die;
    }
  } else {
    http_response_code(404); include('html/blogs/404.html'); die;
  }
  $current_page = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  $url = $blog->get_blogger_branding($username, 'gravurl');
  $img = 'assets/blogs/images/'.$_GET['user'].'.png';
  file_put_contents($img, file_get_contents($url));
  $fbimg = 'https://afpayday.com/assets/blogs/images/'.$_GET['user'].'.png';

  header('Content-Type: application/rss+xml');
  echo '<?xml version="1.0" encoding="UTF-8" ?>
    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
      <channel>
        <title>'.ucfirst($blog->get_blogger_branding($username, "fname")).'\'s Payday Blog</title>
        <description>Learn about affiliate marketing and affiliate product reviews.</description>
        <link>https://afpayday.com/'.$username.'</link>
        <copyright>Copyright 2020 Affiliate Payday</copyright>
        <language>en-us</language>
        <managingEditor>admin@afpayday.com (Bruce Bates)</managingEditor>
        <pubDate>Sun, 23 Feb 2020 09:50:44 -0700</pubDate>
        <webMaster>admin@afpayday.com (Bruce Bates)</webMaster>
        <atom:link href="https://afpayday.com/'.$username.'/rss/" rel="self" type="application/rss+xml" />
        <image>
          <url>'.$fbimg.'</url>
          <title>'.ucfirst($blog->get_blogger_branding($username, "fname")).'\'s Payday Blog</title>
          <link>https://afpayday.com/'.$username.'</link>
          <description>'.ucfirst($blog->get_blogger_branding($username, "fname")).'\'s Photo</description>
          <width>144</width>
          <height>144</height>
        </image>
        <item>
          <title>Test</title>
          <guid>https://afpayday.com/'.$username.'</guid>
        </item>
      </channel>
    </rss>
  ';
?>

根据 w3 验证器,我的提要已正确编码。https://validator.w3.org/feed/check.cgi?url=https%3A%2F%2Fafpayday.com%2Fviraladmin%2Frss%2F

但是浏览器并没有像我期望的那样对待它。

Firefox 尝试将提要下载为文件。

Chrome、Opera 和 Edge 将提要显示为代码,而不是将其显示为文档树,这是我在查看 RSS 提要时通常看到的。

只有 Internet Explorer 似乎可以正确处理它并显示“您想订阅此提要”选项。

提要在这里:https ://afpayday.com/viraladmin/rss/

我希望它在浏览器中看起来更像https://www.feedforall.com/sample.xml

我究竟做错了什么?

标签: phpxmlrss

解决方案


推荐阅读