404 Page Not Found The page you requested was not found.- CodeIgniter - php

Hello guys i try to working on CodeIgniter 1.7.1 i have done step to step installing
but its showing Error
404 Page Not Found
The page you requested was not found.
here is codes i used
controller home.php
class Home extends Controller {
function __construct()
{
parent:: __construct();
//$this->output->enable_profiler();
$this->load->library('DX_Auth');
}
Models homemodel.php
class HomeModel extends Model {
function __construct()
{
// Call the Model constructor
parent::Model();
}
.htaccess
RewriteCond $1 !^(index\.php|assets|xcache|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
i using localhost "XAMPP"
please help me
and main index.php
<?php
error_reporting(E_ALL);
$system_folder = "system";
$application_folder = "application";
if (strpos($system_folder, '/') === FALSE)
{
if (function_exists('realpath') AND #realpath(dirname(__FILE__)) !== FALSE)
{
$system_folder = realpath(dirname(__FILE__)).'/'.$system_folder;
}
}
else
{
// Swap directory separators to Unix style for consistency
$system_folder = str_replace("\\", "/", $system_folder);
}
define('EXT', '.'.pathinfo(__FILE__, PATHINFO_EXTENSION));
define('FCPATH', __FILE__);
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
define('BASEPATH', $system_folder.'/');
if (is_dir($application_folder))
{
define('APPPATH', $application_folder.'/');
}
else
{
if ($application_folder == '')
{
$application_folder = 'application';
}
define('APPPATH', BASEPATH.$application_folder.'/');
}
/*
|---------------------------------------------------------------
| LOAD THE FRONT CONTROLLER
|---------------------------------------------------------------
|
| And away we go...
|
*/
require_once BASEPATH.'codeigniter/CodeIgniter'.EXT;
/* End of file index.php */
/* Location: ./index.php */
Server error Fatal error: Class 'Memcache' not found in /hermes/bosoraweb075/b2180/ipg.djsaifnycom/paly/system/application/controllers/home.php on line 21
function index()
{
$data['memcache'] = new Memcache;
$data['memcache']->pconnect('localhost', 11211) or $memcache = false;
//$this->output->cache(60);
$this->load->model('dx_auth/UserModel', 'user');
$this->load->model('homemodel');
$data['title'] = "Home";
if($this->dx_auth->is_logged_in())
{
$query = $this->user->get_user_by_id($this->session->userdata('DX_user_id'));
//now we get personalized
$row = $query->row();
$data['feedFilter'] = $row->feed_filter;
$data['feedView'] = $row->feed_view;
if($data['feedFilter'] == 'tagged')
{
$data['feedList'] = null;
$data['feedList'] = $data['memcache']->get('feed' . $data['feedFilter'] . $row->feed_view);
if($data['feedList'] == null)
{
$data['albums'] = $this->homemodel->getTagged();
}
} else {
$data['feedList'] = null;
$data['feedList'] = $data['memcache']->get('feed' . $data['feedFilter'] . $row->feed_view);
if($data['feedList'] == null)
{
$data['albums'] = $this->homemodel->getFeedNoUser();
}
}
//$this->output->enable_profiler();
$this->template->write('title', 'Home');
$this->template->write_view('content', 'home/index', $data, TRUE);
$this->template->render();
} else {
$data['feedFilter'] = 'all';
$this->load->helper('cookie');
if(get_cookie('unravel_feedView'))
{
$data['feedView'] = 0;
} else {
$data['feedView'] = 1;
}
//this would be generic feed here
$data['feedList'] = null;
$data['feedList'] = $data['memcache']->get('feed' . $data['feedFilter'] . $data['feedView']);
if($data['feedList'] == null)
{
$data['albums'] = $this->homemodel->getFeedNoUser();
}
$this->template->write('title', 'Home');
$this->template->write_view('content', 'home/index', $data, TRUE);
$this->template->render();
}
//$this->load->view('home/index', $data);
//$this->output->enable_profiler(TRUE);
}
the line is
$data['memcache'] = new Memcache;

Maybe the .htaccess is not in the correct directory.. you may want to check it, should be inside your project directory. if so,
put this in your .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

You might want to also check your httpd.conf file and see if apache is allowed to "honor" your .htaccess file. Search for the AllowOverride command and change it from AllowOverride None (the default) to AllowOverride All.
ALSO: Do not forget to restart the httpd server afterwards.

Related

routing in MVC doesn't work in server, but work properly in localhost

i made a simple mvc with routing system. When i deployed it in 000webhost to be tested, all links don't work. They only shown in the URL. No error message.
i tried to change php version on the server to be the same as my php on localhost, it still didn't work
I guess maybe there's something wrong in my htaccess
here is the routing code:
<?php
class App
{
// controller, method, dan parameter
protected $controller = 'Home',
$method = 'index',
$params = [];
public function __construct()
{
$url = $this->parseURL();
// get controller dari url
if (file_exists('app/controllers/' . $url[0] . '.php')) {
$this->controller = $url[0];
// unset untuk menentukan param
unset($url[0]);
}
// call controller
require_once 'app/controllers/' . $this->controller . '.php';
// instansiasi class controller
$this->controller = new $this->controller;
// get method from url
// check if method exist in url
if (isset($url[1])) {
// cek ketersediaan method pada controller
if (method_exists($this->controller, $url[1])) {
$this->method = $url[1];
// unset untuk menentukan param
unset($url[1]);
}
}
// get param from url
// check array
if (!empty($url)) {
$this->params = array_values($url);
}
// run controller and method and param if exist
call_user_func_array([$this->controller, $this->method], $this->params);
}
public function parseURL()
{
if (isset($_GET['url'])) {
$url = rtrim($_GET['url'], '/');
$url = filter_var($url, FILTER_SANITIZE_URL);
$url = explode('/', $url);
return $url;
}
}
}
and here's the htaccess
Options -Multiviews
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L]
RewriteRule !^(public/|index\.php) [NC,F]

Error 403, access denied on infinityfree domain hosting

I'm currently testing my project which has MVC integrated in it upon deploying in a free hosting site i've encountered an error 403 this error didn't appear since the development stage. My current knowledge why this error occurs is maybe the type of directives i've used in my htaccess? or something maybe in the core itself any toughts or suggestions to this particular problem :)
domain/
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
domain/public
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteBase /domain/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>
domain/app
Options -Indexes
domain/app/libraries/Core.php
<?php
class Core {
protected $currentController = 'Pages';
protected $currentMethod = 'index';
protected $params = [];
public function __construct(){
//print_r($this->getUrl());
$url = $this->getUrl();
// Look in BLL for first value\
if($url != NULL){
if(file_exists('../app/controllers/' . ucwords($url[0]). '.php')){
// If exists, set as controller
$this->currentController = ucwords($url[0]);
// Unset 0 Index
unset($url[0]);
}
}
// Require the controller
require_once '../app/controllers/'. $this->currentController . '.php';
// Instantiate controller class
$this->currentController = new $this->currentController;
// Check for second part of url
if(isset($url[1])){
// Check to see if method exists in controller
if(method_exists($this->currentController, $url[1])){
$this->currentMethod = $url[1];
// Unset 1 index
unset($url[1]);
}
}
// Get params
$this->params = $url ? array_values($url) : [];
// Call a callback with array of params
call_user_func_array([$this->currentController, $this->currentMethod], $this->params);
}
public function getUrl(){
if(isset($_GET['url'])){
$url = rtrim($_GET['url'], '/');
$url = filter_var($url, FILTER_SANITIZE_URL);
$url = explode('/', $url);
return $url;
}
}
}

PHP site run correct on the localhost:8000 but gives erreurs on XAMPP or other server. How to create .htaccess?

This is my first experience to create a site in PHP.
My project run correct on the php interne server , but not on the Xampp ni on the server ovh
ovh serveur erreur: App\Router::run(): Failed opening required '/home/myla/www/views/.php' (include_path='.:/usr/share/php': var $view false
localhost:8000 work correct: var $view post/index
XAMPP erreur : Trying to access array offset on value of type bool :
var $view false
The probleme is in the var $view in the function run().
public function run ():self
{
$match = $this->router->match();
$view= $match['target'] ;
$params= $match['params'];
$router= $this;
$isAdmin= strpos($view, 'admin/') !== false;
$isUser =strpos($view, 'user/') !== false;
if(!$isAdmin && !$isUser){
$layout = 'layouts/default';
}
if($isUser){
$layout = 'user/layouts/default';
}
if ($isAdmin) {
$layout = 'admin/layouts/default';
}
try{
ob_start();
require $this->viewPath . DIRECTORY_SEPARATOR . $view . '.php';
$content = ob_get_clean();
require $this->viewPath . DIRECTORY_SEPARATOR . $layout . '.php';
} catch (ForbiddenException $e) {
header('Location: ' . $this->url('login') . '?forbidden=1');
die();
}
return $this;
}
I use run() in the index.php :
$router = new App\Router(dirname(__DIR__) . '/views');
$router
->get('/', 'post/index', 'home')
->get('/blog/category/[*:slug]-[i:id]', 'category/show', 'category')
->get('/blog/[*:slug]-[i:id]', 'post/show', 'post')
->match('/login','auth/login','login')
->match('/register','auth/register','register')
->post('/logout','auth/logout','logout')
->run();
I try to create .htaccess to re-write the rule, but i didnt found the good configuration.
File index.php is in the folder public and folders public,src,views are in the racine of the projet .
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /public/index.php [L]
Its not work.
Can you kindly help me to configurate .htaccess
Thanks en advance.
Here is a good configuration:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]

How to prevent 403, 400 errors URL forwarding?

Site works good when user enter any url which doesn't exist and forward request to error controller.
But
If you write a script in url site throw 403 error
If you write some asp codes site throw 400 error
How can i prevent this and forward them to custom 403 and 404 pages? I tried forward with htaccess but i couldn't succeed it.
Another problem:
If you write ANY ascii code in adress bar, bootstrap forward to welcome page (controller ->index.php) .How is possible?
Directory structures, htaccess and bootstrap codes are below. Thank you for any help.
Directory structure:
/config
/libs
-bootstrap.php
/controllers
/models
/views
/public_html
-index.php
htaccess
htaccess
htaccess in main directory
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public_html/ [L]
RewriteRule (.*) public_html/$1 [L]
</IfModule>
htaccess in public_html directory
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
index.php in public_html
<?php
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(dirname(__FILE__)));
require_once (ROOT . DS . 'libs' . DS . 'bootstrap.php');
$app = new Bootstrap();
bootstrap.php in libs
<?php
class Bootstrap {
function __construct() {
$url = isset($_GET['url']) ? $_GET['url'] : null;
$url = rtrim($url, '/');
$url = explode('/', $url);
print_r($url);
if (empty($url[0])) {
require '../controllers/index.php';
$controller = new Index();
$controller->index();
return false;
}
$file = '../controllers/' . $url[0] . '.php';
if (file_exists($file)) {
require $file;
} else {
$this->error();
return false;
}
$controller = new $url[0];
// calling methods
if (isset($url[2])) {
if (method_exists($controller, $url[1])) {
$controller->{$url[1]}($url[2]);
} else {
$this->error();
}
} else {
if (isset($url[1])) {
if (method_exists($controller, $url[1])) {
$controller->{$url[1]}();
} else {
$this->error();
}
} else {
$controller->index();
}
}
}
function error() {
require '../controllers/error.php';
$controller = new Error();
$controller->index();
return false;
}
}

Themes outside application

I read this post and I want to use similar solution, but with db.
In my site controller after():
$theme = $page->get_theme_name(); //Orange
Kohana::set_module_path('themes', Kohana::get_module_path('themes').'/'.$theme);
$this->template = View::factory('layout')
I checked with firebug:
fire::log(Kohana::get_module_path('themes')); // D:\tools\xampp\htdocs\kohana\themes/Orange
I am sure that path exists. I have directly in 'Orange' folder 'views' folder with layout.php file.
But I am getting: The requested view layout could not be found
Extended Kohana_Core is just:
public static function get_module_path($module_key) {
return self::$_modules[$module_key];
}
public static function set_module_path($module_key, $path) {
self::$_modules[$module_key] = $path;
}
Could anybody help me with solving that issue?
Maybe it is a .htaccess problem:
# Turn on URL rewriting
RewriteEngine On
# Put your installation directory here:
# If your URL is www.example.com/kohana/, use /kohana/
# If your URL is www.example.com/, use /
RewriteBase /kohana/
# Protect application and system files from being viewed
RewriteCond $1 ^(application|system|modules)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ / [PT,L]
RewriteRule ^(media) - [PT,L]
RewriteRule ^(themes) - [PT,L]
# Allow these directories and files to be displayed directly:
# - index.php (DO NOT FORGET THIS!)
# - robots.txt
# - favicon.ico
# - Any file inside of the images/, js/, or css/ directories
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|static)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
Could somebody help?
What I am doing wrong?
Regards
[EDIT]
My controller code:
class Controller_Site extends Controller_Fly {
public static $meta_names = array('keywords', 'descriptions', 'author');
public function action_main() {
$this->m('page')->get_main_page();
}
public function action_page($page_title) {
$this->m('page')->get_by_link($page_title);
}
public function after() {
$page = $this->m('page');
$metas = '';
foreach(self::$meta_names as $meta) {
if (! empty($page->$meta)) {
$metas .= html::meta($page->$meta, $meta).PHP_EOL;
}
}
$theme = $page->get_theme_name();
Kohana::set_module_path('themes', Kohana::get_module_path('themes').'/'.$theme);
$menus = $page->get_menus();
$this->template = View::factory('layout')
->set('theme', $theme)
->set('metas', $metas)
->set('menus', $menus['content'])
->set('sections', $page->get_sections())
->set_global('page', $page);
if ($page->header_on) {
$settings = $this->m('setting');
$this->template->header = View::factory('/header')
->set('title', $settings->title)
->set('subtitle', $settings->subtitle)
->set('menus', $menus['header']);
}
if ($page->sidebar_on) {
$this->template->sidebar = View::factory('sidebar', array('menus' => $menus['sidebar']));
}
if ($page->footer_on) {
$this->template->footer = View::factory('footer');
}
parent::after();
}
}
and parent controller:
abstract class Controller_Fly extends Controller_Template {
protected function m($model_name, $id = NULL) {
if (! isset($this->$model_name)) {
$this->$model_name = ORM::factory($model_name, $id);
}
return $this->$model_name;
}
protected function mf($model_name, $id = NULL) {
return ORM::factory($model_name, $id);
}
}
[Edit 2]
Previous link to post was dead, link was:
http://forum.kohanaframework.org/comments.php?DiscussionID=5744&page=1#Item_0
My guess is that your controller has a __construct() method and you aren't calling parent::__construct
Actually, I think for kohana V3 __construct needs to also be passed the $request object as follows:
public function __construct(Request $request)
{
parent::__construct($request);
}
I realized that I need to init all modules once again:
$theme = $page->get_theme_name();
Kohana::set_module_path('themes', Kohana::get_module_path('themes').'/'.$theme);
Kohana::modules(Kohana::get_modules());
Now I don't have an error. Instead I am getting white screen of death:
$this->template is null
:(
[EDIT]
Now I know, I had:
$this->template = View::factory('layout')
->set('theme', $theme)
->set('metas', $metas)
->set('menus', $menus['content'])
->set('sections', $page->get_sections())
->set_gobal('page', $page);
Ofcourse I forgot that set_global doesn't return $this :D
Anyway everything working now :)
I have one more question about efficiency. I am calling Kohana::modules() second time in request flow. Is this a big deal according to efficiency?
Regards

Categories