Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Name of page itself?

5 views
Skip to first unread message

Sonnich Jensen

unread,
Feb 28, 2012, 4:58:03 AM2/28/12
to
Hi

I have not worked with PHP for 2+ years, now again and need to refill
my brain...

How can I get the name of the main page?

Say, index.php includes menu.php, how do I get the name of the main
page, in this case index.php?
Next say page1.php, page2.php etc?

Sonnich

tdk2fe

unread,
Feb 28, 2012, 5:14:53 AM2/28/12
to
Magic constants - in this case __FILE__.

http://php.net/manual/en/language.constants.predefined.php

crankypuss

unread,
Feb 28, 2012, 5:23:18 AM2/28/12
to
There is really no way to answer that question in an absolute sense, for
example the "main page" for my web code is "index.php" and *everything*
goes through that.

If you're working with the usual stuff out of the box, you can use
phpinfo() to see which variable you'd like to use to figure out what
you're dealing with... look at things like $_SERVER["DOCUMENT_ROOT"],
$_SERVER["SCRIPT_FILENAME"], $_SERVER["SCRIPT_NAME"],
$_SERVER["PHP_SELF"] for starters.

bill

unread,
Feb 28, 2012, 8:50:40 AM2/28/12
to
I use: basename(__FILE__)

Captain Paralytic

unread,
Mar 1, 2012, 6:16:26 AM3/1/12
to
A php file is NOT the same as a web page. A single php file may have
the ability to generate more than one page. Alternatively many php
files may be used to generate 1 page.

Can you explain why you need to get this information? Then we might be
able to help you get the information that you need.

"Álvaro G. Vicario"

unread,
Mar 1, 2012, 7:01:12 AM3/1/12
to
El 28/02/2012 10:58, Sonnich Jensen escribió/wrote:
> I have not worked with PHP for 2+ years, now again and need to refill
> my brain...
>
> How can I get the name of the main page?
>
> Say, index.php includes menu.php, how do I get the name of the main
> page, in this case index.php?

If I understood correctly, it'll be one of these:

$_SERVER['SCRIPT_FILENAME']
$_SERVER['SCRIPT_NAME']
$_SERVER['PHP_SELF']

Please note that they all refer to the _file_ name (which can show up
the URL or not).

If it isn't any of them:

print_r($_SERVER);

> Next say page1.php, page2.php etc?

No entiendo :-?


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
Message has been deleted

The Natural Philosopher

unread,
Mar 1, 2012, 7:57:30 AM3/1/12
to
Tim Streater wrote:
> In article
> <f244fbdd-78f1-48b4...@gr6g2000vbb.googlegroups.com>,
> Captain Paralytic <paul_l...@yahoo.com> wrote:
>
>> On Feb 28, 9:58 am, Sonnich Jensen <sonnichjen...@gmail.com> wrote:
>
>> > I have not worked with PHP for 2+ years, now again and need to refill
>> > my brain...
>> >
>> > How can I get the name of the main page?
>> >
>> > Say, index.php includes menu.php, how do I get the name of the main
>> > page, in this case index.php?
>> > Next say page1.php, page2.php etc?
>
>> A php file is NOT the same as a web page. A single php file may have
>> the ability to generate more than one page. Alternatively many php
>> files may be used to generate 1 page.
>
> Or it might generate no pages at all. None of mine do.
>

Fabulous. Write only memory in the computer as well?
Talking of the wrong tool for the job, I once heard of a man trying to
build a battleship out of papier mache.




--
To people who know nothing, anything is possible.
To people who know too much, it is a sad fact
that they know how little is really possible -
and how hard it is to achieve it.

Paul Herber

unread,
Mar 1, 2012, 8:54:12 AM3/1/12
to
On Thu, 01 Mar 2012 12:57:30 +0000, The Natural Philosopher <t...@invalid.invalid> wrote:

>Tim Streater wrote:
>> In article
>> <f244fbdd-78f1-48b4...@gr6g2000vbb.googlegroups.com>,
>> Captain Paralytic <paul_l...@yahoo.com> wrote:
>>
>>> On Feb 28, 9:58 am, Sonnich Jensen <sonnichjen...@gmail.com> wrote:
>>
>>> > I have not worked with PHP for 2+ years, now again and need to refill
>>> > my brain...
>>> >
>>> > How can I get the name of the main page?
>>> >
>>> > Say, index.php includes menu.php, how do I get the name of the main
>>> > page, in this case index.php?
>>> > Next say page1.php, page2.php etc?
>>
>>> A php file is NOT the same as a web page. A single php file may have
>>> the ability to generate more than one page. Alternatively many php
>>> files may be used to generate 1 page.
>>
>> Or it might generate no pages at all. None of mine do.
>>
>
>Fabulous. Write only memory in the computer as well?

Nothing unusual about a PHP script that generates no output. How about a script that
receives an IPN email, updates a database and sends out an email. No web browser involved
at all.
Cron can start PHP scripts ...



--
Regards, Paul Herber, Sandrila Ltd.
http://www.sandrila.co.uk/

Paul Herber

unread,
Mar 1, 2012, 8:59:45 AM3/1/12
to
On Thu, 01 Mar 2012 13:54:12 +0000, Paul Herber <pa...@pherber.com> wrote:

>Nothing unusual about a PHP script that generates no output. How about a script that
>receives an IPN email, updates a database and sends out an email. No web browser involved
>at all.
>Cron can start PHP scripts ...

s/IPN email,/IPN,/


Scott Johnson

unread,
Mar 1, 2012, 9:02:35 AM3/1/12
to
Actually __FILE__ may not give you the results you expect all depending
on where it is processed.

It will hold the value of the actual page where it is located which
could not be the actual page being displayed but in a script called by
the display page.

This would be common for display page to have an included file which
lets say has a link back to the itself. Using __FILE__ on the
processing page will then link it to the actual processing page rather
then the display page. In this case using $_SERVER vars mentioned
earlier would give predictable results (again depending on the server,
for instance my dev box does not return URI but the production box does)
but I do believe 'PHP_SELF' is more predictable.

Now a very good use for __FILE__ would be error routines/messages along
with __LINE__ and others to help report errors on an actual script page.

Scott Johnson

unread,
Mar 1, 2012, 9:04:15 AM3/1/12
to
On 3/1/2012 4:57 AM, The Natural Philosopher wrote:
> Tim Streater wrote:
>> In article
>> <f244fbdd-78f1-48b4...@gr6g2000vbb.googlegroups.com>,
>> Captain Paralytic <paul_l...@yahoo.com> wrote:
>>
>>> On Feb 28, 9:58 am, Sonnich Jensen <sonnichjen...@gmail.com> wrote:
>>
>>> > I have not worked with PHP for 2+ years, now again and need to refill
>>> > my brain...
>>> >
>>> > How can I get the name of the main page?
>>> >
>>> > Say, index.php includes menu.php, how do I get the name of the main
>>> > page, in this case index.php?
>>> > Next say page1.php, page2.php etc?
>>
>>> A php file is NOT the same as a web page. A single php file may have
>>> the ability to generate more than one page. Alternatively many php
>>> files may be used to generate 1 page.
>>
>> Or it might generate no pages at all. None of mine do.
>>
>
> Fabulous. Write only memory in the computer as well?
> Talking of the wrong tool for the job, I once heard of a man trying to
> build a battleship out of papier mache.
>
>
>
>

Hmmm.

Seems sort of a shortsighted comment.

What would you use for doing something for example as simple as MySQL DB
maintenance from a cron job?

But also I would have to say if you are using PHP, then the display page
would indeed have php code on it (even as simple as a single line
include/require) in which case pulling the page name is going to be the
same.

And if the battleship is only a display model on a small shelf then
paper mache seems feasible.

The Natural Philosopher

unread,
Mar 1, 2012, 9:06:48 AM3/1/12
to
and you CAN build battleships out of papier mache.

which was the point..

The Natural Philosopher

unread,
Mar 1, 2012, 9:10:40 AM3/1/12
to
Scott Johnson wrote:
> On 3/1/2012 4:57 AM, The Natural Philosopher wrote:
>> Tim Streater wrote:
>>> In article
>>> <f244fbdd-78f1-48b4...@gr6g2000vbb.googlegroups.com>,
>>> Captain Paralytic <paul_l...@yahoo.com> wrote:
>>>
>>>> On Feb 28, 9:58 am, Sonnich Jensen <sonnichjen...@gmail.com> wrote:
>>>
>>>> > I have not worked with PHP for 2+ years, now again and need to refill
>>>> > my brain...
>>>> >
>>>> > How can I get the name of the main page?
>>>> >
>>>> > Say, index.php includes menu.php, how do I get the name of the main
>>>> > page, in this case index.php?
>>>> > Next say page1.php, page2.php etc?
>>>
>>>> A php file is NOT the same as a web page. A single php file may have
>>>> the ability to generate more than one page. Alternatively many php
>>>> files may be used to generate 1 page.
>>>
>>> Or it might generate no pages at all. None of mine do.
>>>
>>
>> Fabulous. Write only memory in the computer as well?
>> Talking of the wrong tool for the job, I once heard of a man trying to
>> build a battleship out of papier mache.
>>
>>
>>
>>
>
> Hmmm.
>
> Seems sort of a shortsighted comment.
>
> What would you use for doing something for example as simple as MySQL DB
> maintenance from a cron job?

C, script? anyone of a zillion better tools than PHP..
Currently I use C.


>
> But also I would have to say if you are using PHP, then the display page
> would indeed have php code on it (even as simple as a single line
> include/require) in which case pulling the page name is going to be the
> same.
>
> And if the battleship is only a display model on a small shelf then
> paper mache seems feasible.

You would be surprised actually at how tough a material it is.

Ok its not quite carbon fibre..laminate.. but actually if you had
nothing else, it WOULD work.

Which is my point. PHP is not a particularly brilliant language. There
are better, for all other applications that do NOT expect you to
routinely switch between echoed output and simple-style coding.

Why not use one?

Jerry Stuckle

unread,
Mar 1, 2012, 10:05:40 AM3/1/12
to
Paul, you're arguing with an idiot.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================

Denis McMahon

unread,
Mar 1, 2012, 10:23:26 AM3/1/12
to
I'm not sure quite what you mean.

Do you (a) just want the trailing filename, or do you want the trailing
filename relative to some arbitrary point in (b) the local file
structure, or (c) an http request url?

The reason I ask is twofold:

1) You don't clarify whether you expect filenames in sub directories to
include path information or not. I could assume you do, I could assume
you don't, instead I choose to confirm your expectation in such
circumstances.

2) If you do expect path information, then although for "http://host/
file" where "file" is at "<docroot>/file", "file" will generally be the
same for a, b and c, and in many webservers this is probably the case,
there are probably also many webservers where due to directory aliasing
in the server, or the use of links (is shortcuts what Ms calls them?) in
the file system and directory structure, or for some other reason, the
filename, the "path+file" url components and the actual filesystem
location of the file (whether absolute or relative to some arbitrary
point) may bear no obvious relationship whatsoever to each other.

Hence, although I see many answers in this thread that address a flat
single directory situation, I'm not 100% sure, partly because I'm not
sure what you actually expect in such cases, that they will give the
answers you expect in every situation in which you might conceivably
deploy them.

Rgds

Denis McMahon
Message has been deleted
Message has been deleted

Scott Johnson

unread,
Mar 1, 2012, 6:28:20 PM3/1/12
to
Why not use C, script? Well if all your classes are coded in PHP why
not use those same classes in your cron job? That way as the needs of
the project such as a DB change, you only need to focus on the changes
in the PHP class and not ensure your C or zillion other scripts are
changed accordingly.

Arno Welzel

unread,
Mar 2, 2012, 12:31:06 PM3/2/12
to
The Natural Philosopher, 2012-03-01 13:57:

> Tim Streater wrote:
>> In article
>> <f244fbdd-78f1-48b4...@gr6g2000vbb.googlegroups.com>,
>> Captain Paralytic <paul_l...@yahoo.com> wrote:
>>
>>> On Feb 28, 9:58 am, Sonnich Jensen <sonnichjen...@gmail.com> wrote:
>>
>>> > I have not worked with PHP for 2+ years, now again and need to refill
>>> > my brain...
>>> >
>>> > How can I get the name of the main page?
>>> >
>>> > Say, index.php includes menu.php, how do I get the name of the main
>>> > page, in this case index.php?
>>> > Next say page1.php, page2.php etc?
>>
>>> A php file is NOT the same as a web page. A single php file may have
>>> the ability to generate more than one page. Alternatively many php
>>> files may be used to generate 1 page.
>>
>> Or it might generate no pages at all. None of mine do.
>>
>
> Fabulous. Write only memory in the computer as well?
> Talking of the wrong tool for the job, I once heard of a man trying to
> build a battleship out of papier mache.

XAseco is a good example. And Nadeo has quite extensive examples how to
use the RPC interface of Trackmania with PHP ;-)


--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
0 new messages