I am totally a newbie.. here is the code i have it working on another site or two but now it won't work here.. what am I doing wrong?
<?php
//we need to set a var to find what page we are on
$pageOn = basename($_SERVER);
//this is used for the title bar
$mItem = $pageOn;
?>
<title>new|innovative technology | HVAC systems|VairTEX Canada Inc| <?=$mItem;?></title>
{headtag}

<body>
<?php
echo $pageOn;
?>

Dani AI

Generated

A few quick, practical notes to help future readers who land here:

The original symptoms here usually come from one of three things: passing the wrong value to a filename helper, short-tag behavior, or accidentally mixing two different PHP fragments (as later discovered). A robust, modern way to derive a page name for a title is to extract the path component and then use pathinfo so you get a clean filename (no query string, no array misuse):

ini_set('display_errors', 1);
error_reporting(E_ALL);

$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$pageName = pathinfo($path, PATHINFO_FILENAME);

If you prefer a direct script-name approach, pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_FILENAME) works too. These avoid passing the entire $_SERVER array into a function that expects a string.

Good catch by about tag syntax: historically short open tags could be disabled. The short-echo form (<?= ... ?>) is safe on modern PHP (always available since PHP 5.4), but if running older installs or mixed environments, use full tags or verify the PHP version and server config. The PHP manual details tag behavior here: PHP tags — manual.

Useful troubleshooting checklist:

  • Turn on error reporting during development (remove in production).
  • var_dump($_SERVER) to see exactly which keys are available.
  • Check includes/partials for duplicated code blocks or variables (mixing snippets can overwrite values).
  • Ensure files are served as PHP (correct extension, server config) and not saved with a UTF-8 BOM which can break output ordering.

References: pathinfo and parse_url docs on php.net are helpful for edge cases.

Recommended Answers

All 2 Replies

Member Avatar for Member #120589

Looks like you're using short tags. They don't work on every server - depends on the php settings.

<?=$mItem;?>

Do

<?php echo $mItem;?>

Instead.

I don't understand why you're doing this:

$mItem = $pageOn;

Why not just use $pageOn?

Thanks I figured out I was actually using 2 parts of different php bits.. duh.. blonde moment..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.