如何动态地将值从php脚本传递到另一个脚本?

发布于 2024-10-12 18:04:26 字数 429 浏览 0 评论 0原文

我想将 url 值从 php 脚本传递到另一个。我有一个数据库,其中存储了一些提要。我给这些提要赋予了一些权重值,并且 php 脚本根据它们的权重随机获取提要 url。我想要获取脚本抓取的提要 url,然后将此 url 传递到另一个 php 脚本中,在该脚本中它将用 simplepie 进行解析以显示其内容。

我在这里发布两个文件的代码:

这是第一个随机抓取提要的脚本 http://pastebin.com/2ciQ87Es 这是第二个脚本,我想在其中传递值并解析提要 http://pastebin.com/eN5qG29e

你有什么可以推荐的吗? 提前致谢

i want to pass a url value from a php script to another.I have a database in which i have stored some feeds.I have given some weight values to these feeds and a php script grabs a feed url randomly based on their weights.I want to take the feed url which has been grabbed by the script and then pass this url in another php script where it will be parsed with simplepie in order to show its content.

I am posting the codes of the two files right here:

this is the first script which grabs randomly the feed
http://pastebin.com/2ciQ87Es
this is the second script in which i want to pass the value and makes the parsing of the feed
http://pastebin.com/eN5qG29e

Have you something to recommend??
thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

春夜浅 2024-10-19 18:04:27

您可以将从数据库中抓取 feed url 包装在一个函数中,然后像任何其他 php 文件一样包含该文件,然后调用该函数。

//// feedgrabber.php
<?php
function grabber(){
    $query = "SELECT * FROM `feeds`";

    //takes all the feed that are declared
    $result = mysql_query($query);
    $data   = array();
    while($output = mysql_fetch_assoc($result)) {
        $data[] = $output;                  // assigns feeds to an array called $data, one after the other, in they go!

    }

    return randomchoice($data);            // finds a random feed by calling the function
}
?>

然后在您需要的页面上:

require('feedgrabber.php');
$feed = grabber();

You could wrap grabbing the feed url from the database in a function, and just include that file like any other php file, and then call that function.

//// feedgrabber.php
<?php
function grabber(){
    $query = "SELECT * FROM `feeds`";

    //takes all the feed that are declared
    $result = mysql_query($query);
    $data   = array();
    while($output = mysql_fetch_assoc($result)) {
        $data[] = $output;                  // assigns feeds to an array called $data, one after the other, in they go!

    }

    return randomchoice($data);            // finds a random feed by calling the function
}
?>

and then on the page where you need it:

require('feedgrabber.php');
$feed = grabber();
痴情换悲伤 2024-10-19 18:04:26

$_SESSION 还不够吗?

在第一个脚本中:

session_start();
$_SESSION['session_name'] = 'value';

在第二个脚本中:

session_start();
print $_SESSION['session_name'];

再考虑一下,您是否不能将查询字符串中的值传递到第二页。

second-page.php?key=value

Would a $_SESSION not suffice?

In the first script:

session_start();
$_SESSION['session_name'] = 'value';

In the second script:

session_start();
print $_SESSION['session_name'];

On second thoughts, could you not pass the value in a query string, to the second page.

second-page.php?key=value
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文