Jump to content

Get page name?


EchoFool

Recommended Posts

Is there a way to get the page name that the function is in ..rather than the page the user is viewing?

 

So example:

 

index.php

// code here
include 'bleh.php';
//code

 

and in the bleh.php has a function to get the name of that file which would return "bleh.php".

 

Because at moment because its included in index.php im getting a result of index.php as a returned variable for function:

strtolower($_SERVER['PHP_SELF'])

 

What function should I use?

Link to comment
https://forums.phpfreaks.com/topic/133514-get-page-name/
Share on other sites

I'm not sure if this is possible.  But consider this, if you are including the file that means at some point you explicitly know the name of the file you are including.  So either save the name of the files you are including, or approach the problem you are having from a different angle.

 

Just a suggestion.

Link to comment
https://forums.phpfreaks.com/topic/133514-get-page-name/#findComment-694442
Share on other sites

Yeah use __FILE__

 

The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path with symlinks resolved whereas in older versions it contained relative path under some circumstances

 

Ignore my asshole comment from before :)

 

$this_file_name = basename(__FILE__);

Link to comment
https://forums.phpfreaks.com/topic/133514-get-page-name/#findComment-694460
Share on other sites

Sometime ago...

 

I had a page /menu/index.php. In this page, I used the normal html layout, so, I a gave the page a title

<head>

<title>menu</title>

</head>

 

Everytime i included it, the overall page beocomes called 'menu'

 

So perhaps this is what you should do, include the page first thing, then echo the page title

Link to comment
https://forums.phpfreaks.com/topic/133514-get-page-name/#findComment-694551
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.