MVC script architecture

I am writing a social network with MVC architecture, it works localhost (wampserver) correctly, but when I upload it to a real host, I get this error at http://example.com/

Warning: require_once(views/index/index.php): failed to open stream: No such file or directory in /home3/farazenc/public_html/fb/views/index.php on line 14

Fatal error: require_once(): Failed opening required 'views/index/index.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home3/farazenc/public_html/fb/views/index.php on line 14

      

and my method doesn't work, for example when I go http://example.com/index/register should show registration form but show 404

my main file: .htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

      

index.php

<?php
session_start();
require_once './config.php';
require_once './lib/database.php';
require_once ('./lib/function.php');
$connect = database::connect();

function __autoload($classname) {
    $directrey = array('controllers', 'models');
    for ($i = 0; $i < sizeof($directrey); $i++) {
        if (file_exists($directrey[$i] . '/' . $classname . '.php')) {
            require_once ($directrey[$i] . '/' . $classname . '.php');
        }
    }
}

if (isset($_GET['url'])) {
    $url = $_GET['url'];
    $split = preg_split('/[\/\\\]/', $url);
    if (sizeof($split) == 1) {
        if (!file_exists('controllers/' . $split[0] . 'Controller.php')) {
            require_once ('./controllers/CheckPage.php');
            CheckPageController::check($split[0]);
        } else {

            $classname = $split[0] . 'Controller';
            $Controller = new $classname();
        }
    } elseif (sizeof($split) == 2) {
        if (file_exists('controllers/' . $split[0] . 'Controller.php')) {
            if (empty($split[1])) {

                $classname = $split[0] . 'Controller';
                $Controller = new $classname();
            } else {

                $classname = $split[0] . 'Controller';
                $Controller = new $classname();
                if (method_exists($Controller, $split[1])) {
                    $Controller->$split[1]();
                } else {
                    require_once ('./views/404.php');
                }
            }
        } else {
            require_once ('./views/404.php');
        }
    }
} else {
    require_once ('./controllers/IndexController.php');
    $IndexController = new IndexController();
}
if (isset($_POST['Action'])) {
    $ajax = new Ajax();
    $ajax->$_POST['Action']();
}

      

controller.php

<?php

abstract class Controller {

    public function render($file) {
        if (!isset($_POST['Action'])) {
            global $split;
            $d = empty($split) ? 'index' : $split[0];
            $content = "views/$d/$file.php";
            require_once ('views/index.php');
        }
    }
    public function user_views($file){
        if (isset($_SESSION['user'])){
            require_once ('views/user/'.$file.'.php');
        }  else {
            require_once ('views/index.php');
        }
    }
    public function admin_views($file){
        if (isset($_SESSION['admin'])){
            global $split;
            $d = empty($split) ? 'index' : $split[0];
            $content = "views/$d/$file.php";
            require_once ("views/admin/admin.php");
        }  else {
            require_once ('views/admin/login.php');
        }
    }
}

      

IndexController.php

class IndexController extends Controller {

    public function __construct() {
        global $split;
        if (empty($split[1])) {
            $this->render('index');
        }
    }

    public function register() {
        $this->render('register');
    }
}

      

view / index.php:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>social network</title>
    <link href="<?php echo URL ?>/css/style.css" rel="stylesheet">
    <script type="text/javascript" src="<?php echo URL ?>/js/ajax.js"></script>
    <script type="text/javascript" src="<?php echo URL ?>/js/jquery.js"></script>
</head>
<body>
<div style="width:1000px;height:650px;margin:50px auto;">
    <div id="content">
        <?php
        require_once($content);
        ?>
    </div>
    <div id="ads" style="margin-right:15px;">
        <img src="<?php echo URL ?>/images/ads-120.jpg">
        <img src="<?php echo URL ?>/images/ads-120.jpg">
    </div>
</div>
</body>
</html>

      

what is the problem and how can i fix it?

+3


source to share


1 answer


I've had a similar problem in the past. If the file resolution is correct (755/644), I advise you to check SELinux (for RHEL / CentOS, etc.). SELinux is configured by default to allow httpd to work on files in the / var / www / html directory, but not outside this directory.

If such software works (try the sestatus command), you can disable it by opening your SELinux config file (usually / etc / selinux / config) and changing the line:

SELINUX=enforcing

      

in

SELINUX=disabled

      

and then reboot the system.

If the sestatus command should show something like this:

SELinux status:             disabled

      



and now check the code again (but make sure you activate SELinux after these tests). if it helps, you just need to configure it accordingly using the command:

$ chcon -R --type=httpd_sys_content_t /path_to_document_root_of_you_great_site

      

or a more permanent solution (better way):

$ semanage fcontext -a -t httpd_sys_content_t '/path_to_document_root_of_you_great_site(/.*)?'
$ restorecon -R -v /path_to_document_root_of_you_great_site

      

if you need httpd to be able to change files, use "httpd_sys_rw_content_t" instead of "httpd_sys_content_t"

PS I'm sorry for my english

Link:

+1


source







All Articles