PHP filter $ _SERVER ['PHP_SELF']

I need to filter out the untrusted $ _SERVER ['PHP_SELF'] varialbe. This is a good approach:

function filterPhpSelf($str) 
{
    $phpself = basename(__FILE__);
    $str = substr($str, 0, strpos($str,$phpself)) . $phpself;
    return $unsafeStr;
}

      

where $ str is $ _SERVER ['PHP_SELF']?

0


source to share


2 answers


1) Your code will throw an error on startup.



2) $_SERVER['PHP_SELF']

unsafe. Unsafe use is unsafe.

+2


source


Yes, it will work. Though you might want to change:

return $unsafeStr;

      



to

return $str;

      

0


source







All Articles