简体   繁体   中英

How to remove the included file in PHP

I"m loading a file in start of PHP. I have declared some activity and assign them to buttons which are aligned left and right side of HTML document. On click of each button will included some Other PHP file but I want to remove the previous loaded on startup file before including any other file.

Here is my code

  <?php // php file on startup of file include("dashboard.php"); $activity = $_REQUEST['activity']; if($activity) { if($activity == 'addMember'){ include("addMember.php"); remove("dashboard.php"); } if($activity == 'dashboard'){ } if($activity == 'issueBooks'){ include("issueBooks.php"); } if($activity == 'returnBooks'){ include("returnBooks.php"); } <?php 

I tried with

  if($activity == 'addMember'){
                            include("addMember.php");
                            remove("dashboard.php");

                        }

But since I"m very new to PHP, it didn't work as expected.

Any Help anyone.

That isn't how include works. When you include a file, the contents of that file are executed at that point in the code. There's no straightforward way to undo that.

It looks like you want the dashboard activity to be the default view if no activity has been selected yet. To do that, you can just include it only when there is no activity value in request, or when the dashboard activity has been specifically requested.

if (empty($_REQUEST['activity']) || $_REQUEST['activity'] == 'dashboard') {
    include 'dashboard.php';
}

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