doublel83422 2012-02-27 17:18
浏览 29
已采纳

带有php的RSS和查询中的变量

I'm trying to build a simple RSS feed for multiple users but i am facing problems with mysql and the feed.

Ive done a showrss.php and an RSS.php I have followed a tutorial on this, and it works as should out of the box. But, im trying to build it, using var's on the mysql query populating the RSS.

so the showrss.php will do this :

require_once "XML/RSS.php";
$rss =& new XML_RSS("http://domain.com/RSS.php");
$rss->parse();
foreach ($rss->getItems() as $item) {
  echo "<li><a href=\"" . $item['link'] . "\">" . $item['title'] . 
"</a></li>
";
}

Calling up the RSS.php file. The only thing wrong with the RSS.php is the mysql query. IT simply wont work with variables in the query, and im wondering if any of you guys could point me in the right direction.

This works :

$query = "select * from article where full_name = 'myname' limit 15";

this does'nt work :

$full_navn = $_SESSION['full_name'];
$query = "select * from article where full_name = '".$full_navn."' limit 15";

However, loading the RSS.php straight in the browser with the variable does work. Any ideas on how to get my variable into rss.php when viewing it through showrss.php ?

Greatly appreciate any input.

  • 写回答

1条回答 默认 最新

  • dszn2485 2012-03-07 18:11
    关注

    Pass your variable via $_GET to the RSS feed and avoid any possible missing session variable.

    Your showrss.php file would be something like this for a user with the name of flamingcarrot:

    $rss =& new XML_RSS("http://domain.com/RSS.php?fullname=flamingcarrot");
    

    Then your RSS.php file would be something along the lines of:

    $full_navn = $_GET['full_name'];
    $query = "select * from article where full_name = '".$full_navn."' limit 15";
    

    If you haven't already, and since it's going to be fiddadling with your SQL statements, bone up some on avoiding some SQL injection attacks with how to properly clean up that SQL query before you actually run it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?