The notation "?p=1" only makes sense within the context of an HTTP request. If you are using filesystem includes, this will not work but instead will generate an error, as your filenames to not include "?p=1".
It is possible, depending on your PHP configuration, to do HTTP includes:
include ('
But I do not, repeat DO NOT, recommend doing this to include a script on the same filesystem. It's slower and much more server resource-intensive.
Anyway, it's probably not a good idea to get into the habit of including files multiple times if for no other reason than rerunning identical code multiple times goes against the entire reason for subroutines.
I recommend that you in file1.php create a user-defined function, include the file once, then invoke the defined function twice with two different inputs:
file1.php:
Code:
<?php
function foo ($a)
{
switch ($a)
{
case 1:
print "ABCD";
break;
case 2:
print "XYZ";
break;
}
}
?>
[BTW, elseif is evil and should never be used. It adds nothing unique to the language and if overused it can reduce code readability. I took the liberty of rewriting your code using a switch()]
Then in file2.php:
Code:
<?php
include ('file1.php');
foo(1);
foo(2);
?>
Want the best answers?
Ask the best questions!
TANSTAAFL!!