简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM