Dinamik nasıl varsayılan sayfayı ayarlamanız gerekir dahil?

2 Cevap

Bu PHP kodu kullanıyorum:

 if (isset($_GET['c'])) {

    $pages = array("home", "upload", "signup");

    if (in_array(strtolower($_GET['c']), $pages)) 
        include('pages/'.$_GET['c'].'.php'); 
    else echo "Page not found =(";

}

Ben bu yüzden varsayılan sayfa Bu kod ile home.php olacak bu nasıl yapmalıyım?

2 Cevap

Ziyaretçi geçersiz sayfasını belirtir zaman hala bir "Sayfa bulunamadı" hatası istiyorum varsayarak, bunu şöyle yapabiliriz:

if (isset($_GET['c'])) {
    if (in_array(strtolower($_GET['c']), $pages)) 
        include('pages/'.$_GET['c'].'.php'); 
    else echo "Page not found =(";
} else {
    include('pages/home.php');
}

Ne bu böyle bir şey:

$page = 'home';
if (isset($_GET['c'])) {
    $pages = array("home", "upload", "signup");
    if (in_array(strtolower($_GET['c']), $pages))  {
        $page = strtolower($_GET['c'])
    }
}

include('pages/' . $page . '.php');

BTW: "Varsayılan" I "sayfa bulunamadı değilse, o varsayılan birini içeren" anladım


Also : if you files names are lower-case, you should use the lowercase name when including -- you are already useing lowercase for the comparison, so why not for the include ?

Eğer bir Windows ortamında Gelişen varsa, isimleri harf duyarlı değildir, ancak Linux üzerinde dosyaları - ve bir Linux sunucu üzerinde dağıtmak eğer ... Ben sana ne olacağını tahmin edelim ;-)