0

For some reason the h1 only says Welcome to Arma 3 Life Highway Patrol's

Any ideas?

<?php

//This file will contain the page name and the credits!

function thisPage($page){
    if ($page == 'sops.php'){
        $Npage = 'SOPs';
                return $Npage;

    }elseif ($page == 'changelog.php'){
        $Npage = 'Website Changelog';
                return $Npage;

    }elseif ($page == 'ftodocuments.php'){
        $Npage = 'FTO Documents';
                return $Npage;

    }elseif ($page == 'index.php'){
        $Npage = 'Homepage';
                return $Npage;

    }elseif ($page == 'login.php'){
        $Npage = 'FTO Login Page';
                return $Npage;

    }elseif ($page == 'socialstuff.php'){
        $NPage = 'Social Stuff';
                return $Npage;
    }else{
        return false;
    }
}
?>

<?php

$findPage = (basename($_SERVER['PHP_SELF']));
$thisPageName =  thisPage($findPage);

?>
<h1>Welcome to the Arma 3 Life Highway Patrol's <?php echo $thisPageName ?></h1>
<p> Website created by Austin Sharp and assisted by Greyson Henley.</p>
roullie
  • 2,830
  • 16
  • 26
Austin M-S
  • 49
  • 5

3 Answers3

0

You can use this $findPage = basename($_SERVER['SCRIPT_FILENAME']);

It will give the filename and print the proper output.

Rolen Koh
  • 719
  • 2
  • 11
  • 21
  • "try this" is not a good answer. explain why this may work – CodeGodie Apr 01 '16 at 03:42
  • 1
    @CodeGodie:- It will work because I just checked it. So may be try word is not exactly the word I should use but there are other solutions so thats why I said try using it and if you like it then keep it. – Rolen Koh Apr 01 '16 at 03:44
  • thanks for fixing the "try this" answer. it looks better now – CodeGodie Apr 01 '16 at 03:51
  • please explain what is the difference between using `basename($_SERVER['PHP_SELF'])` and `basename($_SERVER['SCRIPT_FILENAME'])`. Why is he wrong? – CodeGodie Apr 01 '16 at 03:56
0

the problem is your variables. You have two different variables:

 $NPage = 'Social Stuff';
 return $Npage;

$NPage and $Npage they do not match.

CodeGodie
  • 12,116
  • 6
  • 37
  • 66
0

I actually just tested the code on MAMP and it worked as it should (saved the file as index.php). What server are you testing this on?

Shot in the dark, but try changing $_SERVER['PHP_SELF'] to $HTTP_SERVER_VARS['PHP_SELF'].

Maybe you could try phpinfo() to see if global php variables are empty.

ben721sg
  • 33
  • 1
  • 7