CodeIgniter object controller not found - php

I am using codeIgniter 3.x. I load a view containing a form that submits to User.php controller but whenever I hit the submit button it redirect to this url "http://localhost/signup/Users/register" and it always gives "Object not found! The requested URL was not found on this server."
following is my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /signup/index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /signup/index.php
</IfModule>
following is autload helper in autload.php
$autoload['helper'] = array('url','form');
following is config.php
$config['base_url'] = 'http://localhost/signup/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
following is how I open a form and close it in Welcome.php view.
<?php echo form_open("Users/register", $attributes);?>
<?php echo form_close(); ?>
Following is Users.php controller
class Users extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session', 'form_validation', 'email'));
$this->load->database();
$this->load->model('user_model');
$this->load->view('user_registration_view');
}
function index()
{
$this->register();
}
function register()
{
//set validation rules
$this->form_validation->set_rules('fname', 'First Name', 'trim|required|alpha|min_length[3]|max_length[30]|xss_clean');
$this->form_validation->set_rules('lname', 'Last Name', 'trim|required|alpha|min_length[3]|max_length[30]|xss_clean');
$this->form_validation->set_rules('email', 'Email ID', 'trim|required|valid_email|is_unique[user.email]');
$this->form_validation->set_rules('password', 'Password', 'trim|required|md5');
$this->form_validation->set_rules('cpassword', 'Confirm Password', 'trim|required|matches[password]|md5');
//validate form input
if ($this->form_validation->run() == FALSE)
{
// fails
$this->load->view('user_registration_view');
}
else
{
//insert the user registration details into database
$data = array(
'fname' => $this->input->post('fname'),
'lname' => $this->input->post('lname'),
'email' => $this->input->post('email'),
'password' => $this->input->post('password')
);
// insert form data into database
if ($this->user_model->insertUser($data))
{
// send email
if ($this->user_model->sendEmail($this->input->post('email')))
{
// successfully sent mail
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">You are Successfully Registered! Please confirm the mail sent to your Email-ID!!!</div>');
redirect('user/register');
}
else
{
// error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error. Please try again later!!!</div>');
redirect('user/register');
}
}
else
{
// error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error. Please try again later!!!</div>');
redirect('user/register');
}
}
}

The problem with your htaccess so change it to default
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
And in config
$root=(isset($_SERVER["HTTPS"]) ? "https://" : "http://").$_SERVER["HTTP_HOST"];
$root.= str_replace(basename($_SERVER["SCRIPT_NAME"]), "", $_SERVER["SCRIPT_NAME"]);
$config["base_url"] = $root;

If your application is under your signup folder ( as it appears by your .htaccess file ) then you need to do the following...
.htaccess
This lives in the same folder as your application. i.e the same folder as the system index.php file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
As your URL is http://localhost/signup/ which you have set correctly in your $config['base_url'] that should work.
I just created a dummy test site and tested it.
Let me know if that works.

Filename should be same as class name Users.php Class Users extends CI_Controller

I think you made mistake while redirecting ...
replace :
redirect('user/register');
with :
redirect('Users/register'); OR redirect('Users/register','refresh');

Related

CI page not found

page error
My htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
My Controller
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Auth extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('form_validation');
}
public function index()
{
$this->form_validation->set_rules('username', 'Email', 'required|trim');
$this->form_validation->set_rules('password', 'Email', 'required|trim');
if ($this->form_validation->run() == FALSE) {
# code...
$data['title'] = 'Login';
$this->load->view('templates/auth_header', $data);
$this->load->view('auth/login');
$this->load->view('templates/auth_footer');
} else {
$this->_login();
}
}
anyone know my problem? I think my syntax is correct but the page is still not found.
anyone help me, I'm still a beginner in the field of programmers
Please add this htaccess file in application folder.It may helps
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
Your htaccess file is in outside the application folder.This was also needed.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
**First, you check, that the post data is checked if the condition or else condition inside echo and exit the post data.**
public function index()
{
$this->form_validation->set_rules('username', 'Email', 'required|trim');
$this->form_validation->set_rules('password', 'Email', 'required|trim');
if ($this->form_validation->run() == FALSE) {
echo " If stmt ";
exit();
# code...
$data['title'] = 'Login';
} else {
echo " else stmt";
exit();
$this->_login();
}
}
Please change your file name like (auth/Login) first letter capital

page redirect issue codeigniter : 404 error

I'm creating an application using CodeIgniter.
When I enter the correct email and password I should be redirected to dashboard but I get this redirection:/auth/login and it shows
I may clarify that I allowed mod_rewrite , added the write base_url and allowed connection on apache
My Config.php
$config['base_url'] = 'http://127.0.0.1:8000/stock-v2/';
My controller :
public function login()
{
$this->logged_in();
$this->form_validation->set_rules('email', 'Email', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == TRUE) {
// true case
$email_exists = $this->model_auth->check_email($this->input->post('email'));
if($email_exists == TRUE) {
$login = $this->model_auth->login($this->input->post('email'), $this->input->post('password'));
if($login) {
$logged_in_sess = array(
'id' => $login['id'],
'username' => $login['username'],
'email' => $login['email'],
'logged_in' => TRUE
);
$this->session->set_userdata($logged_in_sess);
redirect('dashboard', 'refresh');
}
else {
$this->data['errors'] = 'Incorrect username/password combination';
$this->load->view('login', $this->data);
}
}
else {
$this->data['errors'] = 'Email does not exists';
$this->load->view('login', $this->data);
}
}
else {
// false case
$this->load->view('login');
}
}
*/
public function logout()
{
$this->session->sess_destroy();
redirect('auth/login', 'refresh');
}
Can anyone help?
Change your .htaccess file. Paste this in .htaccess in your app directory (in same level to applications) and will works :
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
And in conf.php:
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].'/stock-v2/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Then use regirect like this without refresh:
redirect(base_url('dashboard'));
Check in http.conf do you allow override for your domain?
<Directory "/var/www">
AllowOverride All
# Allow open access:
Require all granted
</Directory>
You must configure your base URL.
If you're work on the local server then try this:
$config['base_url'] = 'http://localhost/stock-v2/';
Otherwise (live)
$config['base_url'] = 'http://<put your domain here>';

Unable to redirect to a new page - CodeIgniter

I have a login system that works, but on the redirect function it gives me the error The requested URL "http://localhost/musiclear/index.php/welcome" cannot be found or is not available. Please check the spelling or try again later.
This is where I am using it (login.php):
function validate_credentials() {
$this->load->model('membership_model');
$query = $this->membership_model->validate();
if ($query) { // if users credentials validated
$data = array('usernames' => $this->input->post('username'),
'is_logged_in' => true);
$this->session->set_userdata($data); //set session data
redirect('welcome', 'refresh'); //redirect to home page
} else { //incorrect username or password
$this->index();
}
}
This is where I am directing it to (welcome.php):
class Welcome extends CI_Controller {
public function index() {
$this->home();
}
public function home() {
$this->load->model('model_users');
$data['title'] = 'MVC Cool Title'; // $title
$data['page_header'] = 'Intro to MVC Design';
$data['firstnames'] = $this->model_users->getFirstNames();
// just stored the array of objects into $data['firstnames] it will be accessible in the views as $firstnames
$data['users'] = $this->model_users->getUsers();
$this->load->view('home_view', $data);
}
}
Im thinking it is something wrong with the path, or where its linking to but im not sure. This is my directory setup:
Can someone please tell me whats wrong and how I can make it link to my page? Thanks so much
Have you created the .htaccess in your application folder?
Maybe this can work for your project:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /musiclear/index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /musiclear/index.php
</IfModule>
You are welcome

Codeigniter "No input file specified." error when submitting form?

I am stuck and cannot seem to figure my issue out. I am trying to write a basic "Contact Us Form" using Codeigniter for the first time. My form on my view looks like this..
<div style='float: left; padding-right: 55px; padding-left: 35px;'>
<?php
$this->load->helper('form');
echo form_open('pages/emailsender'); ?>
Contact Us:<br />
<?php
echo form_input('name', 'Enter Your Name');
echo form_input('email', 'Enter Your Email');
echo "<br />";
echo form_textarea('message', 'Enter your message here, thanks for taking the time to contact us!');
echo "<br />";
echo form_submit('submit', 'Send Message!');
echo form_reset('reset', 'Reset Form');
echo form_close();
?>
</div>
and my controller pages.php looks like this..
<?php
class Pages extends CI_Controller {
public function index(){
$this->load->view('templates/header');
$this->load->view('home');
$this->load->view('templates/footer');
}
public function home(){
$this->load->view('templates/header');
$this->load->view('home');
$this->load->view('templates/footer');
}
public function about(){
$this->load->view('templates/header');
$this->load->view('about');
$this->load->view('templates/footer');
}
public function services(){
$this->load->view('templates/header');
$this->load->view('services');
$this->load->view('templates/footer');
}
public function reviews(){
$this->load->view('templates/header');
$this->load->view('reviews');
$this->load->view('templates/footer');
}
public function specials(){
$this->load->view('templates/header');
$this->load->view('specials');
$this->load->view('templates/footer');
}
public function contact(){
$this->load->view('templates/header');
$this->load->view('contact');
$this->load->view('templates/footer');
}
public function emailsender(){
$this->load->view('templates/header');
$this->load->view('contact');
$this->load->view('templates/footer');
}
}
I have the "emailsender" function just redirecting me back to the same page as a test, but it won't even do that?! I get a "No input file specified." error every time. I read this post on stackoverflow Codeigniter no input file specified error but it doesn't seem to resolve my issue. My config file looks like this..
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
$config['base_url'] = 'http://mywebsitename.com';
$config['index_page'] = "";
$config['uri_protocol'] = "AUTO";
any ideas why I am getting the No input file specified error?
Change your .htaccess to look like this
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Notice the ? mark in the last line. Previously this line was something like this RewriteRule ^(.*)$ index.php/$1 [L]
Also make sure to add this line RewriteBase / in your .htaccess
Change Your .htaccess like that
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
Hope It will works for you...
thanks
Change:
echo form_open('pages/emailsender'); ?>
To:
echo form_open_multipart('pages/emailsender'); ?>
form_open_multipart adds the enctype="multipart/form-data" to the form tag.
You need to use the direct link instead of the short hand of the form open tag. Like this:
echo form_open(‘http://example.com/welcome/emailsender’);
instead of this:
echo form_open(‘welcome/emailsender’);

CodeIgniter URL not working

I wonder if anyone can help me??? I'm using CodeIgniter to create a small Login Screen. However, every time I call the function to validate the details using the CodeIgniter form helper. A 404 error keeps showing stating that CodeIgniter can't find the URL. My code for the 'View' file looks like:
<!doctype html>
<html>
<head>
<title>CodeIgniter Prototype</title>
<!-- CSS/LESS Code Links -->
<link rel = "stylesheet" href = "<?php echo base_url();?>css/style.css" type = "text/css"/>
</head>
<body>
<div class = "login_wrapper">
<h1>ONESG OneInvoice Exporter</h1>
<?php
echo form_open('login/check_login');
echo form_input('username', '', 'placeholder = "Enter Username"');
echo form_password('password', '', 'placeholder = "Enter Password"');
echo form_submit('submit', 'Login');
echo form_close();
?>
</div>
</body>
</html>
My Controller Code Looks Like:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller {
public function index() {
$this->load->view('login_form');
}
public function check_login() {
$this->load->model('login_model');
$query = $this->login_model->validate();
if ($query) {
$data = array (
'username' => $this->input->post('username'),
'is_logged_in' => true
);
$this->sessions->set_userdata($data);
redirect('site/members_area');
}
else {
$this->index();
}
}
}
Check your folder structure whether you have .htaccess file.
if not add file name called .htaccess
and add following code to file
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Add this in .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Then in routes.php in config add
$route["members_area/(.*)"] = 'site/members_area/$1';

Categories