PHP路由的性能和安全性

时间:2018-06-13 11:57:44

标签: php performance .htaccess security routing

这是我在PHP上的第一个路由系统。你可以看到它非常简单。 有关它的任何建议或提示可以使它更好吗?我想做得更好,所以我可以在真实的网站上使用它。 首先我包括db connect,然后获取URL,如果URL有特殊索引,如post id或post name,则包括post.php或者如果$ sp_link [4] == profile,则加载profile.php。 PHP代码:

<?php
    require_once 'inc/header.php';
    include_once 'inc/nav.php';


    $actual_link = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    // echo $actual_link;
    $sp_link = explode("/", $actual_link);
    print_r($sp_link);


    $sql ='SELECT * from posts WHERE post_id=? AND post_name=?';
    $stmt=$pdo->prepare($sql);
    $stmt->execute([@$sp_link[5], @$sp_link[6]]);
    $post=$stmt->fetch();

    if ($sp_link[4] == 'blog' && @$sp_link[5] == '' ) {
        // @include 'blog.php';
        //$page_title = $post->post_title;
    }
    else if ($sp_link[4] == 'profile' && @$sp_link[5] == '' ) {
        @include_once 'profile.php';
    }
    else if ($sp_link[4] == 'login' && @$sp_link[5] == '' ) {
        @include 'login.php';
        $page_title = 'ورود';
    }
    else if ($sp_link[4] == 'signup' && @$sp_link[5] == '' ) {
        @include 'signup.php';
        $page_title = 'ورود';
    }
    else if ($sp_link[4] == 'blog' && @$sp_link[5] == $post->post_id && @$sp_link[6] ==     $post->post_name) {
        @include 'post.php';
        $page_title = $post->post_title;

    }
    else if (($sp_link[4] == '' || $sp_link[4] == 'index' || $sp_link[4] == 'index.php') &&     @$sp_link[5] == '') {
           $page_title = 'سکان آکادمی | آموزش برنامه نویسی';
            include 'home.php';
    }
    else if (($sp_link[4] == 'blog' && $sp_link[5] == '12342') && @$sp_link[6] == '') {
        include_once 'post.php';
    } else {
        include_once '404.php';
    }

这是htaccess

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^.*$ ./index.php

0 个答案:

没有答案
相关问题