php显示当前页面

时间:2017-05-02 12:39:46

标签: javascript php html mysql

我正在尝试显示用户所在的当前页面,并且每次用户访问其他页面时都会更新。这是我到目前为止的代码;

$files = [
'<a href="session.php">'. 'Home' .'</a>' ,
'<a href="sql1.php">'. 'SQL1' .'</a>' ,
'<a href="sql2.php">'. 'SQL2' .'</a>',
'<a href="sql3.php">'. 'SQL3' .'</a>',
'<a href="sql4.php">'. 'SQL4' .'</a>',
'<a href="sql5_1.php">'. 'SQL5_1' .'</a>',
'<a href="sql5_2.php">'. 'SQL5_2' .'</a>',
'<a href="sql6.php">'. 'SQL6' .'</a>',
'<a href="sql7.php">'. 'SQL7' .'</a>',
'<a href="sql8.php">'. 'SQL8' .'</a>',
'<a href="sql9.php">'. 'SQL9' .'</a>',
'<a href="sql10.php">'. 'SQL10' .'</a>',
];

file_get_contents('sql1.php');
file_get_contents('sql2.php');
file_get_contents('sql3.php');
file_get_contents('sql4.php');
file_get_contents('sql5_1.php');
file_get_contents('sql5_2.php');
file_get_contents('sql6.php');
file_get_contents('sql7.php');
file_get_contents('sql8.php');
file_get_contents('sql9.php');
file_get_contents('sql10.php');


echo "Next Page ".$files[array_rand($files)];

1 个答案:

答案 0 :(得分:1)

php有一个Magic constant__FILE__。这将返回当前文件及其文件名的路径。

// Path and file
echo "Current page: " . __FILE__;

// Get only the filename
$split = preg_split('/\//', __FILE__);
echo $split[count($split) - 1];