Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > PHP
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

PHP PHP for some can be one of the hardest website programming codes, so do you need help on your PHP script, if it is php4, php5 or lower this is the place for you for any PHP help.

Google
Reply
 
LinkBack Thread Tools Display Modes
Old 05-20-2007, 5:33 PM   #1
Alan Jones
 
Alan Jones's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default '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.
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Advertisements
Old 05-20-2007, 5:33 PM   #2
shimmyshack
 
shimmyshack's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default 'nested conditional' that can identify parent page?

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.

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #3
Alan Jones
 
Alan Jones's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default 'nested conditional' that can identify parent page?

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.

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #4
shimmyshack
 
shimmyshack's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default 'nested conditional' that can identify parent page?

On 13 May, 00:31, Alan Jones <a...@jalanjones.com> wrote:
> On 12 May 2007 08:48:01 -0700, shimmyshack <matt.fa...@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.


basename($_SERVER['SCRIPT_FILENAME']);
does exactly that, try it.

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #5
Alan Jones
 
Alan Jones's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default 'nested conditional' that can identify parent page?

On 12 May 2007 19:20:20 -0700, shimmyshack <matt.farey@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...

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #6
shimmyshack
 
shimmyshack's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default 'nested conditional' that can identify parent page?

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.

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #7
Alan Jones
 
Alan Jones's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default 'nested conditional' that can identify parent page?

On 13 May 2007 04:41:19 -0700, shimmyshack <matt.farey@gmail.com>
wrote:

>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.


All of your effort is very appreciated, Matt. I'm grateful for the
time you have put into this, but I think I have figured it out.

Apparently, $_SERVER does not like the use of a http web file path
when doing an include. I had been using http://jalanjones.com/...
to specify the path to the file. For the heck of it, just to try
anything, I changed the path to the local file system syntax,
'includes/index_ body.php', and it now works as it should.

I'm using...

if ($_SERVER['PHP_SELF'] == '/index.php'){include('signature.php');}

....without any errors. If I change 'index' to anything else, for
example 'index_2', it does not include the signature or give an
error. The short script is page specific and can be used, with
modified paths, in any file. That's just my speed; keep it simple
for stupid. I have a lot of learning to do and you helped me get
over this hump, thank you.

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #8
shimmyshack
 
shimmyshack's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default 'nested conditional' that can identify parent page?

On May 14, 2:04 am, Alan Jones <a...@jalanjones.com> wrote:
> On 13 May 2007 04:41:19 -0700, shimmyshack <matt.fa...@gmail.com>
> wrote:
>
>
>
> >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.

>
> All of your effort is very appreciated, Matt. I'm grateful for the
> time you have put into this, but I think I have figured it out.
>
> Apparently, $_SERVER does not like the use of a http web file path
> when doing an include. I had been usinghttp://jalanjones.com/...
> to specify the path to the file. For the heck of it, just to try
> anything, I changed the path to the local file system syntax,
> 'includes/index_ body.php', and it now works as it should.
>
> I'm using...
>
> if ($_SERVER['PHP_SELF'] == '/index.php'){include('signature.php');}
>
> ...without any errors. If I change 'index' to anything else, for
> example 'index_2', it does not include the signature or give an
> error. The short script is page specific and can be used, with
> modified paths, in any file. That's just my speed; keep it simple
> for stupid. I have a lot of learning to do and you helped me get
> over this hump, thank you.


if you will need signature included for a set of files you know in
advance you could do this
(this example works for all index.php filenames because it uses
basename, if you need/want to specify filenames by their paths then
remove the basename part, and specify the files in the array including
their paths
$arrFileNamesWhereSignatureShouldAppear = array(
'index.php',
'contact.php'
);
if( in_array(basename($_SERVER['PHP_SELF']),
$arrFileNamesWhereSignatureShouldAppear) )
{
include('signature.php');
}

remember that this is NOT the simple way. All this might appear
simple, but the rub comes later when you relise you have to rewrite
everything to do something that would have been simple if you had
committed to the learning curve earlier.
You are encouraged to look at best practise examples and follow along,
before thinking you can rewrite the book with "5 minute home brew
architecture" trust me I learned this way too!

for instance here's a better way to include stuff. (still old style
non Object Oriented)

mainpage.php
<?php
#find page you are on from request uri
include('functions.php');
$arrayPageParts = get_page_info( $_SERVER['REQUEST_URI'] );
?>
<?php
#css just for this page
echo $arrayPageParts['css'];
'js just for this page
echo $arrayPageParts['js'];
?>
styles/js for everypage go here
<html><head>
<title><?php echo $arrayPageParts['title']; ?></title>
<?php echo output_meta_tag( $arrayPageParts['description']; ?>
<meta tags: language, description, keywords, etc...
<!--some comment-->
</head><body>
<?php
#this ['body'] could instead be
['menu']
more html...
['content']
etc.. so that more html is in the template, and content elsewhere
try to make as little php and html mix as possible, have a template
which is all the html you need, and fill with pure content
echo $arrayPageParts['body']; ?>
<?php echo $arrayPageParts['signature'];
#which of course is not there if the $page leads to this being null
?></body></html>

I mean this is by no means the right way of coding, but it is a very
simple "template"

the idea of includes can be useful but not as usefule as functions
which get the data and return it into an array

Once again, this might be arguably better, its no OO hMVC pattern but
hey it's better than writing condition includes in the main page, keep
on abstracting away your code into functions and return a array of
paragraphs, menu content etc.. free of html, and use while loops and
so on..
this way if you redesign the site, you just redesign the template, and
the content can come from a db or flat files or another website, you
dont care, and that makes it easy to add pages...

anyway matt out.

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #9
Alan Jones
 
Alan Jones's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default 'nested conditional' that can identify parent page?

On 13 May 2007 18:42:28 -0700, shimmyshack <matt.farey@gmail.com>
wrote:

>if you will need signature included for a set of files you know in
>advance you could do this
>(this example works for all index.php filenames because it uses
>basename, if you need/want to specify filenames by their paths then
>remove the basename part, and specify the files in the array including
>their paths
>$arrFileNamesWhereSignatureShouldAppear = array(
>'index.php',
>'contact.php'
>);
>if( in_array(basename($_SERVER['PHP_SELF']),
>$arrFileNamesWhereSignatureShouldAppear) )
>{
> include('signature.php');
>}
>
>remember that this is NOT the simple way. All this might appear
>simple, but the rub comes later when you relise you have to rewrite
>everything to do something that would have been simple if you had
>committed to the learning curve earlier.
>You are encouraged to look at best practise examples and follow along,
>before thinking you can rewrite the book with "5 minute home brew
>architecture" trust me I learned this way too!
>
>for instance here's a better way to include stuff. (still old style
>non Object Oriented)
>
>mainpage.php
><?php
>#find page you are on from request uri
>include('functions.php');
>$arrayPageParts = get_page_info( $_SERVER['REQUEST_URI'] );
>?>
><?php
>#css just for this page
>echo $arrayPageParts['css'];
>'js just for this page
>echo $arrayPageParts['js'];
>?>
>styles/js for everypage go here
><html><head>
><title><?php echo $arrayPageParts['title']; ?></title>
><?php echo output_meta_tag( $arrayPageParts['description']; ?>
><meta tags: language, description, keywords, etc...
><!--some comment-->
></head><body>
><?php
>#this ['body'] could instead be
>['menu']
>more html...
>['content']
>etc.. so that more html is in the template, and content elsewhere
>try to make as little php and html mix as possible, have a template
>which is all the html you need, and fill with pure content
>echo $arrayPageParts['body']; ?>
><?php echo $arrayPageParts['signature'];
>#which of course is not there if the $page leads to this being null
> ?></body></html>
>
>I mean this is by no means the right way of coding, but it is a very
>simple "template"
>
>the idea of includes can be useful but not as usefule as functions
>which get the data and return it into an array
>
>Once again, this might be arguably better, its no OO hMVC pattern but
>hey it's better than writing condition includes in the main page, keep
>on abstracting away your code into functions and return a array of
>paragraphs, menu content etc.. free of html, and use while loops and
>so on..
>this way if you redesign the site, you just redesign the template, and
>the content can come from a db or flat files or another website, you
>dont care, and that makes it easy to add pages...
>
>anyway matt out.


Thanks, I'll digest all that over time, as I continue learning.

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Featured Websites
Free Space
Free Space
Free Space Free Space
Reply
Tags: , , , ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
help with posting using conditional if Art PHP 3 05-20-2007 5:33 PM
page loading !! Beshoo PHP 3 05-20-2007 5:33 PM
Xfire page MadKad The Games 2 10-31-2006 10:07 AM


Featured Websites




All times are GMT +1. The time now is 7:31 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98