|
Posted by shimmyshack on 05/13/07 11:41
On May 13, 3:44 am, Alan Jones <a...@jalanjones.com> wrote:
> On 12 May 2007 19:20:20 -0700, shimmyshack <matt.fa...@gmail.com>
> wrote:
>
> >> Thank you very much for the help. :) I'll give your recommendation
> >> a run thru, but is there a way to make basename, or a similar
> >> function, simply return the filename of the parent page; the page
> >> the include is in? Thanks again, I really appreciate any help I can
> >> get.
>
> >basename($_SERVER['SCRIPT_FILENAME']);
> >does exactly that, try it.
>
> It returns the filename of the file it is in. I ran...
>
> echo basename($_SERVER['SCRIPT_FILENAME']);
>
> ...from within the 'include' file index_body.php and it returned
> that same filename.
>
> I need the code in the include file to somehow determine, or derive,
> the name of its 'parent' file in a given instance. This procedure
> would be happening within the include file as it resides in the
> parent file.
>
> Again, thanks for racking your brain on this with me. I'm at a total
> loss... :(
That wasnt quite what I expected you to do, I expected you to place
this:
echo basename($_SERVER['SCRIPT_FILENAME']);
inside the included file and run the website as you would normally, if
the included file was indeed included, then you will see a value
different from that of the included name.
I am not sure what you are asking, but I think you are saying
1: "I have files a,b,c... each of which include u and I want to
include e(signature) inside u only when the "top" file is b"
but you could be saying
2: "I have files a,b,c... each of which include u,v,w and I want to
include e(signature) only inside v" - in which case there is an
equally simple answer. just let me know which question you are asking
cos I keep answering 1 and were not getting anywhere! :)
Ultimately there are many ways to skin a cat, but this one just seemed
the easiest.
To see what the value of the variables are do this:
(this will let you convince yourself that you /can/ use this method)
create a file called 1.php, and inside put this:
<?php
echo '<pre>';
echo 'i am file called: ' . __FILE__ . "\n";
echo 'request uri: ' . $_SERVER["REQUEST_URI"] . "\n";
echo 'script name: ' . $_SERVER["SCRIPT_NAME"] . "\n";
echo 'php self: ' . $_SERVER["PHP_SELF"] . "\n";
echo 'script filename: ' . $_SERVER["SCRIPT_FILENAME"] . "\n";
echo "\ni am going to include the next file\n";
include ( '2.php' );
?>
create a file called 2.php and inside put this:
<?php
#echo '<pre>';
echo 'i am file called: ' . __FILE__ . "\n";
echo 'request uri: ' . $_SERVER["REQUEST_URI"] . "\n";
echo 'script name: ' . $_SERVER["SCRIPT_NAME"] . "\n";
echo 'php self: ' . $_SERVER["PHP_SELF"] . "\n";
echo 'script filename: ' . $_SERVER["SCRIPT_FILENAME"] . "\n";
echo "\ni am going to include the next file\n";
include ( '3.php' );
?>
create a file called 3.php and inside put this:
<?php
#echo '<pre>';
echo 'i am file called: ' . __FILE__ . "\n";
echo 'request uri: ' . $_SERVER["REQUEST_URI"] . "\n";
echo 'script name: ' . $_SERVER["SCRIPT_NAME"] . "\n";
echo 'php self: ' . $_SERVER["PHP_SELF"] . "\n";
echo 'script filename: ' . $_SERVER["SCRIPT_FILENAME"] . "\n";
echo "\ni wont include any more files, see how despite the name of the
file changing the others dont, this is because each file is contained
within the first.\n";
?>
save them to the same php enabled web accessible folder and in your
browser call up 1.php
when you view the results you will see what you should have seen the
first time.
Here's the solution using the above method but writing it at the top
in index.php (we are still taling about question 1 here).
1.php
<?php
$myname = basename(__FILE__);
include('2.php');
?>
2.php
<?php
if($myname=='index.php')
{
include_once('signature.php');
}
include('3.php');
?>
or if you want it to appear in an even more nested include so your
head will explode when you come to edit this website in the future
3.php
<?php
if($myname=='index.php')
{
include('signature.php');
}
?>
and so on,
the basic concept is that you need logic somewhere to compare the
value of the script filename with the value you want, and either
have the logic just before the include telling it to be include when
script_filename = index.php
have the logic in the "top" script, and set a variable which ripples
through includes and test for it.
Navigation:
[Reply to this message]
|