0

I've found a couple of "fixes" on this site, none of which have worked for myself.

The code I am using is <title><?php echo ucfirst(pathinfo($_SERVER['PHP_SELF'], PATHINFO_FILENAME));?> | Test</title> which is in a file called navbar.php.

To link the navbar.php file to the actual page being used, I am using the following in [page name].php:

<div id="navbar"></div>

<script>
    $(function(){
        $("#navbar").load("navbar");
    });
</script>

Which places the code from navbar.php into the current page.

The issue is that the title says Navbar | [website name] instead of [page name] | [website name]

Marking this question as a duplicate is invalid as the other questions do not contain what I am asking nor do they have an answer that works for my code.

Thanks in advance.

Anonymous
  • 15
  • 6
  • Possible duplicate of [Get calling file name from include()](https://stackoverflow.com/questions/10265216/get-calling-file-name-from-include) – Sami Kuhmonen Sep 22 '18 at 03:46
  • Possible duplicate of [Get filename of file which ran PHP include](https://stackoverflow.com/questions/10393145/get-filename-of-file-which-ran-php-include) – Shyam Joshi Sep 22 '18 at 04:03

2 Answers2

0

Try to use HTTP_REFERER instead of PHP_SELF as follows. Because PHP_SELF will give the name of the callee file while the HTTP_REFERER gives you the caller file name. As you are interested in the caller name on the title this is the right way

<title><?php echo ucfirst(pathinfo($_SERVER['HTTP_REFERER'], PATHINFO_FILENAME));?> | Test</title>
Rinsad Ahmed
  • 1,877
  • 1
  • 10
  • 28
0

Remove title tag from navbar.php Check the following for the same

navbar.php

    <p>Text or content you want to load in page title</p>

pagetitle.php

    <html>
        <head>
            <title><?php echo ucfirst(pathinfo($_SERVER['PHP_SELF'], PATHINFO_FILENAME));?> | Website Name</title>
        </head>
        <body>
            <div id="navbar"></div>
        </body>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script>
            $(function(){
                $("#navbar").load("navbar.php");
            });
        </script>
    </html>
Bhoomi Joshi
  • 161
  • 1
  • 3