There is no way to remove a file already included.
The code is interpreted on the server side by the PHP module, which also generates the webpage to be viewed on the client side.
This means that every time the user refreshes the page or opens the page, it sends a requirement to the server and the server interprets the server-side code ( server-side ) .
What I mean by this is that there would be no need to remove the include since when a new requirement is made everything is done from the beginning, so if we have a condition:
if($var == true)
{
include "file1.php";
} else {
include "file2.php";
}
In the first request if the variable $var
is equal to true
the file1.php
file will be included, but if another request is made and the $var
variable is falsa
the file2.php
file will be included and the file1.php
file would not exist, because, as I said, when a requirement is made it starts again.
I made a small code to exemplify this, test for yourself.
TestB.php
<?php
echo "Hello from A";
TestA.php
<?php
echo "Hello from A";
Test.php
<?php
$var = $_GET['n'];
switch($var)
{
case 1:
{
include "testA.php";
break;
}
case 2:
{
include "testB.php";
break;
}
}
You will see that when you change the n value in the link (test.php? n = 1 or test.php? n = 2 ) the existing existing file is not included.