将变量从iframe中的PHP页面传递到另一个?

时间:2016-01-14 19:53:50

标签: php iframe

所以最好解释我的项目。 index.php页面包含两个iframe,其中一个iframe链接到business.php,后者显示BBC RSS提要。第二个是显示每篇文章的个别链接。因此,如果要点击business.php中的单个标题链接;它实际上创建了一个变量,转移回index.php,然后用作第二个iframe的源代码,而不是被带到iframe中的那个BBC页面......我希望这是有道理的,我现在试图使用SESSION函数。

index.php

<?php
 if(!isset($_SESSION)) 
            { 
                session_start(); 
            } 
?>

<html>
<head>
    <link rel="stylesheet" type="text/css" href="style.css" /> 
</head>

<body>
<table>
    <col width="15%">
    <col width="42.5%">
    <col width="42.5%">
    <tr>
        <td id="bar">
            Rob's Edition

<ul>            
    <li><a href="index.php?$newsfeed='feeds/business.php'">Business</a></li>
    <li><a href="index.php?$newsfeed='feeds/technology.php'">Technology</a></li>
</ul>
        </td>

<td id="feed">



            <?php

            $newsfeed = "feeds/default.php";

            if (isset($_GET['$newsfeed'])) {
                $_SESSION['$newsfeed'] = $_GET['$newsfeed'];
            }
            echo isset($_SESSION['$newsfeed']) ? "<iframe src={$_SESSION['$newsfeed']} style='border:none' width='100%' height='100%' overflow-y='hidden' color='white'></iframe>" : 'Please choose a topic<br />';  

    ?>

    <td id='frame'> 
            <?php



            //echo isset($_SESSION['$framelink']) ? "<iframe src={$_SESSION['$framelink']} style='border:none' width='100%' height='100%' overflow-y='hidden' color='white'></iframe>" : 'Please choose a topic<br />';  



        echo ($_SESSION['$framelink']);
    ?>     
    </td>  

</body>
</html>

business.php

<?php
 if(!isset($_SESSION)) 
            { 
                session_start(); 
            } 

$framelink = ""
?>

<html>
<head>
    <link rel="stylesheet" type="text/css" href="style.css" /> 
</head>

<body>

<div>
<?php
$rss = simplexml_load_file('http://feeds.bbci.co.uk/news/business/rss.xml?edition=uk'); //BBC Business RSS Feed
$feed1 = "<h1>" . $rss->channel->title . "</h1>" . '<hr>'; //Title of feed 

foreach ($rss->channel->item as $item) {


    $framelink = $item->link;
    $feed1 .= '<h2><a href="business.php?' . $framelink . '">' . $item->title . '</a></h2>'; //Title of article
    $feed1 .=$item->description; //Description of article


}
?>


<?php
if (isset($_GET['$framelink'])) {
                $_SESSION['$framelink'] = $_GET['$framelink'];
            }

echo $feed1; 

?>
</div>
</body>
</html>

0 个答案:

没有答案