开发者

how to pass values from a php script to another dynamically?

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


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


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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜