2017-05-02 4 views
0

私は現在のページを表示しようとしており、ユーザーが別のページに行くたびに更新されます。ここまでは私のコードです。php display current page

$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)]; 
+0

ご質問はありますか? –

+0

マジック定数 '__FILE__'を使用する方法はありますか?ファイルパスだけではなく、ファイルだけを表示していますか? –

答えて

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]; 
+0

ありがとう私はどこかに行っている!とにかく、完全なファイルパスなしでファイル名を持つことができますか? –

+0

はい、あなたは '__FILE__'値の最後の部分を得ることができます。文字列を '/'に分割して答えを更新しました。 – Jerodev

+0

助けてくれてありがとう! –