phpacademy登录/注册清理网址

时间:2015-01-20 11:19:37

标签: php oop clean-urls

我目前正在制作自己的CRM网站应用程序,并且我使用了Alex youtube教程,即使用OOP登录/注册。

此外,我需要将index.php作为动态内容切换器,我只包含页眉和页脚,而内容从存储所有页面的文件夹加载。我相信最终结果应该像www.example.com/index.php?page=profile

我环顾四周,似乎我正在做的事情类似于MVC模式,其中index是根文件,所有内容都是从视图文件夹加载的。

我设法正确完成所有操作,但现在不是显示以下链接:www.example.com/user.php?name = jennifer

我希望它是www.example.com/user/name/jennifer

我试着浏览一下phpacademy论坛,但论坛似乎已经放弃了,有些搜索我找到了一个与我想要的相关的主题,但代码似乎没有用,我得到了同样的东西海报错误。

这是代码:

<?php
// Define the root of the site (this page should be in the root)
define('ROOT', rtrim(__DIR__, '/') . '/');
define('PAGES', ROOT . 'pages/');


// Define "safe" files that can be loaded
$safeFiles = ["login", "regiser", "profile", "changepassword"];


// Get URL
if(isset($_GET['page']) && !empty($_GET['page'])) {
    $url = $_GET['page'];
} else {
    $url = '/';
}


// Remove Path Traversal
$sanatize = array(
    // Basic
    '..', "..\\", '../', "\\", 
    // Percent encoding
    '%2e%2e%2f', '%2e%2e/', '..%2f', '%2e%2e%5c', '%2e%2e', '..%5c',     '%252e%252e%255c', '..%255c',
    // UTF-8 encoding
    '%c1%1c', '%c0%af', '..%c1%9c'
);
$url = str_replace($sanatize, '', $url);
// Prevent Null byte (%00)
// PHP 5.6 + should take care of this automatically, but PHP 5.0 < ....
$url = str_replace(chr(0), '', $url);
// Filter URL
$url = filter_var($url, FILTER_SANITIZE_URL);
// Remove any extra slashes
$url = rtrim($url, '/');
// Make lowercase url
$url = strtolower($url);


// Check current page
$path = PAGES . $url . '.php';
// If the file is in our safe array & exists, load it!
if(in_array($url, $safeFiles) && file_exists($path)) {
    include($path);
} else {
echo "404: Page not found!";
}

我搜索谷歌,但我找不到解决方案,我注意到有人在这个论坛上提问,因此我希望有人可以帮助我。

0 个答案:

没有答案
相关问题