-1

私はサイトを更新する人々の複雑さを最小限に抑えるためのシステムをセットアップしようとしています.

DB を使用できないため、すべてのコンテンツは 2 つの基本フォルダー (/private/content または /private/utilities) のいずれかに存在します。通常の毎日の更新では、ユーティリティ (ページ ラッパー - ヘッダー、ナビゲーション、フッターなどを含む) フォルダーにアクセスする必要はありません。これにより、毎日の編集者に見えるコードの量が最小限に抑えられます。

アクセス可能な有効なセクションのリストを含む配列 ($allowedContent) を作成しました。コードはその配列に対してテストを行い、ユーザーが不適切なコンテンツにアクセスしようとしていないことを確認します。以下のコードでは、これらのリクエストは成功します。他のすべては失敗するでしょう。

  • www.example.com/
  • www.example.com/popup/*
  • www.example.com/test
  • www.example.com/hello
  • www.example.com/foobar

私の質問は次のとおりです。このアプローチの問題として突き出ているものはありますか?

.htaccess

RewriteEngine On
#  Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

PHP

// parse the URL
$requestURI = explode('/', $_SERVER['REQUEST_URI']);
//print_r ($requestURI);

// a list of non-restricted dynamic content
$allowedContent = array("test", "hello", "foobar");
$allowAccess = false; // assume hackers :o

// determine the section
if (!$requestURI[1]) { // none defined - use root/home
    $section = 'home';
    $skin = true;
    $allowAccess = true;
} elseif ($requestURI[1] == 'popup') { // popup - no skin
    $section = $requestURI[2];
    $skin = false;
    $allowAccess = true;
} else {
    if (in_array($requestURI[1], $allowedContent)) { // verify that the requested content is allowed / prevent someone from trying to hack the site
        $section = $requestURI[1];
        $skin = true;
        $allowAccess = true;
    } else { // this would be either a 404 or a user trying to access a restricted directory
        echo "evil laugh"; // obviously, this would change to a 404 redirect
    }
}

コンテンツが呼び出されるコードを追加

// call the relevant content pieces
if ($allowAccess == true) {
    if ($skin == true ) {
        // call wrapper part 1
        include $_SERVER['DOCUMENT_ROOT'] . '/private/utilities/wrapperOpen.php';

        // call aside
        include $_SERVER['DOCUMENT_ROOT'] . '/private/utilities/header.php';

        // call aside
        include $_SERVER['DOCUMENT_ROOT'] . '/private/utilities/aside.php';
    }

    // call CONTENT (based on section)
    include $_SERVER['DOCUMENT_ROOT'] . '/private/content/' . $section . '/index.php';

    if ($skin == true ) {
        // call branding
        include $_SERVER['DOCUMENT_ROOT'] . '/private/utilities/branding.php';

        // call footer
        include $_SERVER['DOCUMENT_ROOT'] . '/private/utilities/footer.php';

        // call wrapper part 2
        include $_SERVER['DOCUMENT_ROOT'] . '/private/utilities/wrapperClose.php';
    }
}
4

1 に答える 1

0

これはうまくいくでしょう。xml を使用してデータを保存することも検討できますが、ファイルが大きくなりすぎた場合は、システム メモリの使用量と読み込み時間を監視する必要があります。可能な場合は分割してください。データベースを使って彼らに話しかけることはできませんか? データベースを使用したウェブホスティングは安価です。

于 2012-06-13T21:45:22.407 に答える