Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #8802
| From | Scott Johnson <noonehome@chalupasworld.com> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Seeking help with relative and absolute paths |
| Date | 2013-03-22 06:12 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <kihl95$mnu$1@dont-email.me> (permalink) |
| References | <d6258610-56e6-423d-82f7-5ab3b3f88eee@googlegroups.com> <kic3uc$ifg$1@dont-email.me> <aqucd5Fmfi7U1@mid.individual.net> <3a0aadc7-316f-46de-bb15-0347af57810d@googlegroups.com> <ar2ehrFj4ofU1@mid.individual.net> |
On 3/22/2013 12:11 AM, J.O. Aho wrote:
> On 22/03/13 05:24, The Frog wrote:
>> Thankyou very much for the replies. I appreciate the help. I have a
>> follow-up question then regarding constants and setting them. If I
>> define a constant say in the sites landing page (eg/index.php) will
>> that constant then remain available for any scripts on pages that
>> follow without having to 'require' them?
>
> <?php
> DEFINE('A', true);
> include "fileB.php";
> ?>
>
> In this case the A would exists in fileB.php, but it's a quite iffy way
> to do it, as if you include fileB.php from another script which don't
> have the define, then the A will be missing and you will end up with an
> error. A constant will only exists after it has been defined and will
> not remain in memory when you load a new page.
>
>> The reason I ask is one of ignorance on my part. Having consulted the
>> php manual on constants I am unable to make a clear determination on
>> their usage and scope. It would seem in my experimentation and
>> learning that a constant does not in fact remain but in fact needs to
>> be re-defined in each unique page change on the users part. While this
>> can be accommodated in the scripts and pages that I write I am
>> wondering if there is a better way? Define once and use many places?
>
> A constant will not magically live into another page, if you want a
> value to be set on pageA and then be accessible on pageB and pageC then
> use $_SESSION[]
>
> see: http://www.php.net/manual/en/intro.session.php
>
>
I think you are true in the aspect of magically appear but if you code
it properly, the CONSTANT will be available for any script/page you need it.
For example:
If you create your config file and put your constants in it, any script
that includes that config file will have that constant visible which at
this point is not much functionally difference then setting data for
each page, but this provides a single location for setting site wide data.
And if you sink your config below the root as discussed earlier then
that data will also be relatively protected.
I use the config and defines for setting SQL criteria, typing friendly
root paths and server side peculiarities.
Then when you move from your Dev site to the Prod site, you only need to
change one file.
You can have separate configs for public and admin as well.
Hope that makes sense.
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Seeking help with relative and absolute paths The Frog <mr.frog.to.you@googlemail.com> - 2013-03-19 21:45 -0700
Re: Seeking help with relative and absolute paths "J.O. Aho" <user@example.net> - 2013-03-20 06:45 +0100
Re: Seeking help with relative and absolute paths Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-20 06:46 -0400
Re: Seeking help with relative and absolute paths "J.O. Aho" <user@example.net> - 2013-03-20 19:10 +0100
Re: Seeking help with relative and absolute paths The Frog <mr.frog.to.you@googlemail.com> - 2013-03-21 21:24 -0700
Re: Seeking help with relative and absolute paths "J.O. Aho" <user@example.net> - 2013-03-22 08:11 +0100
Re: Seeking help with relative and absolute paths The Frog <Mr.frog.to.you@googlemail.com> - 2013-03-22 19:38 +1100
Re: Seeking help with relative and absolute paths Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-22 09:01 -0400
Re: Seeking help with relative and absolute paths "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-03-22 14:33 +0100
Re: Seeking help with relative and absolute paths Scott Johnson <noonehome@chalupasworld.com> - 2013-03-22 06:12 -0700
Re: Seeking help with relative and absolute paths The Frog <Mr.frog.to.you@googlemail.com> - 2013-03-23 23:57 +1100
Re: Seeking help with relative and absolute paths Scott Johnson <noonehome@chalupasworld.com> - 2013-03-23 07:25 -0700
Re: Seeking help with relative and absolute paths "J.O. Aho" <user@example.net> - 2013-03-23 16:24 +0100
Re: Seeking help with relative and absolute paths The Frog <Mr.frog.to.you@googlemail.com> - 2013-03-24 15:09 +1100
Re: Seeking help with relative and absolute paths Scott Johnson <noonehome@chalupasworld.com> - 2013-03-24 07:27 -0700
Re: Seeking help with relative and absolute paths Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-24 12:24 -0400
csiph-web