473,805 Members | 2,172 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'nested conditional' that can identify parent page?


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.
May 11 '07 #1
16 3748
fel
On 11 mayo, 17:42, Alan Jones <a...@jalanjone s.comwrote:
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.

use debug_backtrace () ?

May 11 '07 #2
On May 11, 6:42 pm, Alan Jones <a...@jalanjone s.comwrote:
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.variab les.php#reserve d.variables.ser ver>

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('signat ure.php');

instead of putting signature.php inside common.php under some
condition?

May 11 '07 #3
On 11 May 2007 15:59:55 -0700, fel <fe**********@g mail.comwrote:
>On 11 mayo, 17:42, Alan Jones <a...@jalanjone s.comwrote:
>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.


use debug_backtrace () ?
Thank you for the quick response. I'll check that out and report
back any success.

I was thinking something so simple as declaring a string in the
parent page and getting a conditional statement within the first
include to see it, act on it's presence; decide whether to process
the second include. Shirley this can be done :D
May 11 '07 #4
On 11 May 2007 16:47:16 -0700, ZeldorBlat <ze********@gma il.com>
wrote:
>On May 11, 6:42 pm, Alan Jones <a...@jalanjone s.comwrote:
>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.varia bles.php#reserv ed.variables.se rver>
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('commo n.php');
include('signa ture.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?

May 12 '07 #5
On May 11, 8:36 pm, Alan Jones <a...@jalanjone s.comwrote:
On 11 May 2007 16:47:16 -0700, ZeldorBlat <zeldorb...@gma il.com>
wrote:
On May 11, 6:42 pm, Alan Jones <a...@jalanjone s.comwrote:
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.variab les.php#reserve d.variables.ser ver>

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('signat ure.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_SI GNATURE', true);
include('common .php');

Then, common.php might look something like this:

//output some HTML
if(defined('SHO W_SIGNATURE') && SHOW_SIGNATURE)
include('signat ure.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.

May 12 '07 #6
On 11 May 2007 17:46:48 -0700, ZeldorBlat <ze********@gma il.com>
wrote:
>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_S IGNATURE', true);
include('commo n.php');
First of all, thank you very much for clueing me in on this area of
programming. Without your help, I would still be very lost, 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.

May 12 '07 #7
On May 12, 7:35 pm, Alan Jones <a...@jalanjone s.comwrote:
On 11 May 2007 17:46:48 -0700, ZeldorBlat <zeldorb...@gma il.com>
wrote:
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_SI GNATURE', true);
include('common .php');

First of all, thank you very much for clueing me in on this area of
programming. Without your help, I would still be very lost, 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.
Yes -- look at the following URL:

<http://www.php.net/manual/en/
reserved.variab les.php#reserve d.variables.ser ver>

and try the various variables available to see what they return.

May 13 '07 #8
On 12 May 2007 19:51:19 -0700, ZeldorBlat <ze********@gma il.com>
wrote:
>First of all, thank you very much for clueing me in on this area of
programming. Without your help, I would still be very lost, 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.

Yes -- look at the following URL:

<http://www.php.net/manual/en/reserved.variab les.php#reserve d.variables.ser ver>

and try the various variables available to see what they return.
I went thru that page last night and the most promising seemed to
be 'REQUEST_URI', which is supposed to output, "The URI which was
given in order to access this page; for instance, '/index.html'."

However, both...

echo ($_SERVER['REQUEST_URI']);

and...

echo basename($_SERV ER['REQUEST_URI']);

....returned the name of the file it is in, the include 'child' file,
and not the actual page URL accessed; /index.php. I need the
include script to know if it is being run within index.php.

Again, thanks for racking your brain on this with me. I'm at a
total loss... :(

BTW, might you or anyone be able to help with understanding
'open_basedir restriction'? I received the following error when
trying to use the link() function...

link ("/index.php","/index_body.php" );

Warning: link(): open_basedir restriction in effect.
File(/index.php) is not within the allowed path(s):
(/home/httpd/vhosts/jalanjones.com/httpdocs:/tmp) in
/home/httpd/vhosts/jalanjones.com/httpdocs/index_body.php on line 46

Thanks :)
May 13 '07 #9
At Sun, 13 May 2007 03:26:41 +0000, Alan Jones let his monkeys type:
On 12 May 2007 19:51:19 -0700, ZeldorBlat <ze********@gma il.com>
wrote:

[snip]

I went thru that page last night and the most promising seemed to
be 'REQUEST_URI', which is supposed to output, "The URI which was
given in order to access this page; for instance, '/index.html'."

However, both...

echo ($_SERVER['REQUEST_URI']);

and...

echo basename($_SERV ER['REQUEST_URI']);

...returned the name of the file it is in, the include 'child' file,
and not the actual page URL accessed; /index.php. I need the
include script to know if it is being run within index.php.
It _should_ tell you the top level calling script. Show us what you
are doing exactly please. Btw, I am no fan of include files behaving
differently depending on where they're called from. What if your script
name changes ?
BTW, might you or anyone be able to help with understanding
'open_basedir restriction'? I received the following error when trying
to use the link() function...

link ("/index.php","/index_body.php" );
Open_basedir is a php setting telling the server the top_level directory
from which files can be opened in your scripts. It's commonly set to point
to your httpdocs dir. (In php.ini)
You got this warning because you tried linking files from your server's
root directory. Link takes a filepath, not a url. In other words, remove
the / from the arguments. (Or provide a full path to the file):

link ("index.php","i ndex_body.php") ;

Using the phpinfo() function you can see if open_basedir is set and if so,
to what directory.

HTH
Sh.

May 13 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
4553
by: Paul Morrow | last post by:
I'm hoping that someone can explain why I get the following exception. When I execute the code... ###################################### class Parent(object): class Foo(object): baz = 'hello from Parent.Foo' class Child(Parent): #Foo.baz = 'hello from Child.Foo'
3
5940
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be terminated by pressing ++ and then terminate the process. I searched the entire internet and found out that there could be two things wrong (both of them are mentioned in the bug list on the access
10
3249
by: nimmi_srivastav | last post by:
Below you will see an example of a nested conditional expression that this colleague of mine loves. He claims that it is more efficient that a multi-level if-else-if structure. Moreover, our complexity analyzer tool supposedly does not pick it up. Is it really more efficient? Personally I find this coding style extremely cryptic, misleading and error-prone. I believe that I have removed all traces of proprietary-ness from this coding...
0
5407
by: Ed Allan | last post by:
http://ejaconsulting.com/nestedrepeater/NestedRepeater.txt >-----Original Message----- >Doh! The HTML has all been rendered . . . > >Right click on this link and select 'Save target as ..' >to get the code in a text file. > >Thanks - Ed >
1
1976
by: Roy | last post by:
How is it done? BTW, I'm reposting this here, as the datagrid newsgroup appears functionally comatose... I have a nested datagrid setup. When one updates the child grid using edit, it also updates a field in the parent grid (the parent grid update is done using a simple select query inside the child grid's update sub). All is well, *however* after the update occurs the parent grid is still displaying the old data even though the update...
0
2093
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any help........pls urgent ========================================================= <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm3.aspx.vb" Inherits="TestDatagrids.WebForm3"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">...
2
2834
by: GISmatters | last post by:
I have unbound checkboxes in a nested gridview to allow multi-selection of "child" rows. For context, the parent gridview rows are for large "reports", the child rows are for various specific files comprising each report. I want the user to be able to select an arbitrary collection of report files and have them emailed by clicking an "Email selected files" button. Everything displays properly, including the checkboxes for each child row (each...
1
5033
by: SimonZ | last post by:
I have nested update panels. When I click on button, which is located in parent update panel, I would like that only child update panel is refreshed. Now the both panels are refreshed or none if I set ChildrenAsTriggers="false" on parent update panel. How can I do that? thanks, Simon
0
1658
by: Brian Lowe | last post by:
I'm in a web page and I have hierarchical data so I'm using 2 nested DataList controls. DataList1 is using a data source with rows of , , and where MoreData is a list. DataList1 has an ItemTemplate with Literal controls for Name, ID and Status and a DataList control for MoreData. DataList2 is using MoreData where fields are , and .
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10613
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3846
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.