I am running the following code:

if(is_array($check)) {
                foreach($check as $val) {
                    if($_SERVER['PHP_SELF']==$val) {
                        $show = false;
                        break;
                    } else {
                        echo "<p>".$_SERVER['PHP_SELF']."!=".trim($val)."</p>";
                    }
                }
            }

And I am getting the following output:

/client/scheduled.php!=/client/scheduled.php

Hopefully it's not something dumb on my part, I appreciate any advice.

Dani AI

Generated

This kind of problem almost always comes down to invisible differences between the two strings — trailing/newline/carriage-return characters, a BOM, or other control bytes — or to comparing an unnormalized value while the code that printed the values showed a trimmed/normalized form. resolved it, and the usual fix is to normalize both sides before comparing.

Easy, practical checks to reveal the mismatch:

var_dump($_SERVER['PHP_SELF']);
var_dump($val);
echo 'len: ' . strlen($_SERVER['PHP_SELF']) . ' vs ' . strlen($val);
echo 'hex1: ' . bin2hex($_SERVER['PHP_SELF']);
echo 'hex2: ' . bin2hex($val);

Those will show types, exact lengths, and raw byte sequences so hidden bytes become obvious.

Recommended quick fixes and best practices:

  • Normalize both values before comparing (trim control whitespace; remove BOMs if present).
  • Compare canonical forms (use basename or normalized paths) rather than raw strings when you only care about the filename.
  • When reading lists from files, strip newlines at read time (use the appropriate file-reading option or trim each entry).
  • Avoid using unescaped $_SERVER['PHP_SELF'] in HTML output — escape it with htmlspecialchars() if you must use it.

PHP manual references: $_SERVER variables and trim() for normalization, and var_dump() for debugging.

Aaaand it was something dumb on my part...

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.