|
Posted by Alan Jones on 05/12/07 23:31
On 12 May 2007 08:48:01 -0700, shimmyshack <matt.farey@gmail.com>
wrote:
>On May 11, 11:40 pm, Alan Jones <a...@jalanjones.com> wrote:
>> Hello everyone, any help would be greatly appreciated. :)
>>
>> What I'm trying to do may not be advisable, but here goes...
>>
>> I want a page named signature.php to appear conditionally as
>> an include within another include so that it will, for example,
>> appear in index.php but not in other result pages that use the
>> same top level include.
>>
>> The method would need to determine what page it is inside of
>> during each given instance. I guess something like...
>>
>> if page is index.php then include file else do nothing
>>
>> A 'nested conditional' seems obvious but I don't know how to
>> create an argument that checks the result page file name or
>> otherwise id's that parent page.
>>
>> Obviously, I'm new to PHP and my understanding of basic
>> programming is very limited. I'm also new to the group. I hope
>> to learn quickly, and I look forward to helping others in the
>> future.
>
>make three php pages,
>each containing the following
>apart from the last line
><?php
>echo '<pre>';
>echo "me: " . __FILE__;
>echo $_SERVER["REQUEST_URI"] . "\n";
>echo $_SERVER["SCRIPT_NAME"] . "\n";
>echo $_SERVER["PHP_SELF"] . "\n";
>echo $_SERVER["SCRIPT_FILENAME"] . "\n";
>echo "\n\n";
>include ( '2.php' );
>?>
>inside 2.php the last line should be 3.php
>and inside 3.php theres no include
>
>you will see that __FILE__ always contains the name of the script it
>is in, whether than is included in something else or not.
>whereas $_SERVER['SCRIPT_FILENAME'] doesnt change, it returns 1.php
>because that is the script your are executing, so you can use it to
>find the name of the file that includes the others.
>your basic script would be
>if( basename($_SERVER['SCRIPT_FILENAME'])=='index.php' )
>{
> include( 'signature.php' );
>}
>however if you change your server setup this might not always work, as
>you said before hard coding things like this is generally not a good
>idea. Instead look at the architecture you are building and see if you
>cant handle the whole thing in one function somewhere centrally
>located say in /private/appname/functions
>this way your life is easier later on.
>hope that helps.
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.
[Back to original message]
|