简体   繁体   English

访问其他页面后重定向到index.php

[英]Redirect to index.php when other pages have been accessed

i have this php pages 我有这个PHP页面

index.php index.php

<?php
    include 'viewannouncement.php';
?>

viewannouncement.php viewannouncement.php

<?php     
          $result = mysql_query("SELECT announcement_date,announcement_title,
          announcement_text FROM sp_announcement") or die(mysql_error());  

        echo "<table id=\"newspaper-b\">";
        echo "<thead>";
        echo "<tr>";
        echo "<th scope=\"col\">Date</th>";
        echo "<th scope=\"col\">Title</th>";
        echo "<th scope=\"col\">Announcement</th>";
        echo "</tr>";
        echo "</thead>";

        while($row = mysql_fetch_array( $result )) {
                echo "<tr>";
                echo '<td>' . $row['announcement_date'] . '</td>';
                echo '<td>' . $row['announcement_title'] . '</td>';
                echo '<td>' . $row['announcement_text'] . '</td>';
                echo "</tr>"; 
        } 
        echo "</table>";
        echo "<br>";
        echo "<br>";
?>

in index.php it has a tab which includes and views viewannouncement.php, the problem is when i access the subpages manually it leaves a whitescreen, how can i make it redirect to index.php and still be view able via the tabs in index.php 在index.php中,它有一个包含并查看viewannouncement.php的选项卡,问题是当我手动访问子页面时,它留下了白屏,我如何使其重定向到index.php并仍然可以通过index中的选项卡查看.php

i hope you guys can help me, any help is greatly appreciated 我希望你们能帮助我,任何帮助都将不胜感激

Typically people set a variable to check if a file was included or not, Why not do something like this? 通常,人们设置一个变量来检查是否包含文件,为什么不这样做呢? In your index file 在您的索引文件中

<?php
$fromIndex = true;
include 'viewannouncement.php';
?>

Then in your file viewannouncement.php, try this at the top. 然后在您的文件viewannouncement.php中,尝试顶部的操作。

if(!isset($fromIndex)) {
  header('Location: /index.php');
  die;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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