|
Posted by ZeldorBlat on 05/12/07 00:46
On May 11, 8:36 pm, Alan Jones <a...@jalanjones.com> wrote:
> On 11 May 2007 16:47:16 -0700, ZeldorBlat <zeldorb...@gmail.com>
> wrote:
>
>
>
> >On May 11, 6:42 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.
>
> >You can always find out what the "top-level" script is with
> >$_SERVER['PHP_SELF'] or $_SERVER['SCRIPT_NAME'] then base your
> >decision to include on that.
>
> ><http://www.php.net/manual/en/
> >reserved.variables.php#reserved.variables.server>
>
> I think that may be my answer. :) Thank you, I'll need to read up
> on it a bit and do some testing.
>
> >However, if you want to include something on one page only why
> >wouldn't you just include it on that page? For example, if you want
> >to include "common.php" on every page and "signature.php" on index.php
> >only, why not just put the following on index.php:
>
> >include('common.php');
> >include('signature.php');
>
> >instead of putting signature.php inside common.php under some
> >condition?
>
> My proposed solution is probably overkill. My original problem is
> positioning of the content. All of the content in the first include
> is within a table.
>
> In the parent page, I could create the table structure of the first
> include, break the first include into parts, and populate the cells
> individually with the pieces and parts of the first and second
> include. My problem with that is I want to retain the ability to
> work with, edit, the first include as a single page.
>
> In the parent page, maybe there is a way to specify the position/
> location of one include inside another?
What I would do in that case is define a variable or constant in your
top (index) page before including common.php, then check for it before
including signature.php. That way you aren't limited to only showing
it on index.php, but can instead pick and choose which pages to
include it on.
So, in your index.php (or any other page on which you want to show
the "signature") you would do something like this:
define('SHOW_SIGNATURE', true);
include('common.php');
Then, common.php might look something like this:
//output some HTML
if(defined('SHOW_SIGNATURE') && SHOW_SIGNATURE)
include('signature.php')
//output some more HTML
That's basically the same as checking the value of
$_SERVER['SCRIPT_NAME'] but it gives you a bit more flexibility.
[Back to original message]
|