I have created a small web application using codeigniter.But sometimes when I click back button this error message display. What Should Ido to avoid this matter?
Confirm Form Resubmission
This webpage requires data that you entered earlier in order to be properly displayed. You can send this data again, but by doing so you will repeat any action this page previously performed.
Press the reload button to resubmit the data needed to load the page.
ERR_CACHE_MISS
This is part of my main controller
<?php
ob_start();
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library('session');
$this->load->helper('form');
$this->load->helper('url','html');
$this->load->helper('html');
$this->load->database();
$this->load->library('form_validation');
$this->load->model('Login_model');
$this->load->model('Select');
$this->load->model('ProjectEmployees');
$this->load->model('Employee_model');
$this->load->model('Welcome_model','welcome');
$this->load->model('Welcome_model4','welcome4');
$this->load->model('Welcome_modelPI','welcomePI');
}
function index()
{
$this->load->view('login_view');
}
function logout()
{
// destroy session
$data = array('login' => '', 'uname' => '', 'uid' => '');
$this->session->unset_userdata($data);
$this->session->sess_destroy();
redirect('Home/index');
}
public function MyHome()
{
$this->load->view('template/navigation');
$this->load->view('template/sideNav');
$this->load->view('template/header');
$this->load->view('profile_view2');
$this->load->view('template/footer');
}
It's because you Expiring the Page & not sending the Cache Header to Browser. That's why Browser not Caching those pages and while you hitting back Browser displaying ERR_CACHE_MISS instead of your html view..
ERR_CACHE_MISS (Screen):
Make sure you are not Sending Expire Cache Header
Make sure your page not prevent by Browser Cache
Check your Response Header in Browser Net Panel, to See what Header
being passed by Server
Check if your are using $this->output->set_header() in your
code/controller/hook.
Here are some CodeIgniter Cache Expire Header Code Example..
$this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
$this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
Related
I am not able to flush cache after logout in laravel.
On logout I have done lots things but nothing is working for me . I am not able to find a way in laravel to flush cache on my logout.
return redirect(\URL::previous());
return redirect(\URL::previous());
also tried Clouser class
This Code might help you.
public function logout(Request $request) {
header("cache-Control: no-store, no-cache, must-revalidate");
header("cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
Session::flush();
$request->session()->regenerate();
Session::flash('succ_message', 'Logged out Successfully');
return redirect('signin');
}
For more details please click on this Link.
So I noticed the fact that after a user logs in then clicks on the back button it returns them back to the login page. How do I make it so that it doesn't do that?? The logout version of the code I found to stop clicking the back button to go to secured page from happening doesn't seem to apply to the login problem I'm experiencing.
Here's the code I added to constructor and it seems to have stopped logout from using back to return to secured page:
parent::__construct();
$this->output->set_header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
$this->output->set_header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0');
$this->output->set_header('Cache-Control: post-check=0, pre-check=0', FALSE);
$this->output->set_header('Pragma: no-cache');
$this->load->helper('url');
$this->load->driver('cache');
}
Also added a $this->cache->clean() at logout
Here is the sample codes or you, In your login controller check the exist login session.
function __construct() {
parent::__construct ();
$valid_login = $this->session->userdata ( 'valid_login' );
if ($valid_login == 1) {
redirect ( base_url('homeController') );
}
return true;
}
public function checklogin() {
$name = $this->input->post ( 'username' );
$pass = $this->input->post ( 'password' );
$this->load->model ( 'loginModel' );
if ($this->loginModel->login ( $name, $pass )) {
$this->session->set_userdata ( 'username', $name );
$this->session->set_userdata ( 'valid_login', 1 );
return true;
} else {
return false;
}
}
Now in the home controller check for the login session else log out and redirect to the login page like bellow.
function __construct() {
parent::__construct ();
$valid_login = $this->session->userdata ( 'valid_login' );
if ($valid_login == "")
redirect ( 'loginController' );
}
you could try this..
function __construct()
{
parent::__construct();
//$this->load->model('model_session');
$this->load->model('model_vanshaval');
$this->load->model('model_session');
if($this->model_session->check_logged()==FALSE){
redirect('welcome');
}
you could write this constructor in welcome controller to check whether user is logged in or not..
I'm working with codeIgniter. I am making a login form which checks the members details with the database.
However when I click to login I get this error message:
The requested URL /waitronmain/login.php/login/validate_credentials was not found on this server.
However this is my login.php file and as you can see validate_credentials() does exist.
class Login extends CI_Controller{
function index()
{
$data['main_content'] = 'login_form';
$this->load->view('includes/template', $data);
}
function validate_credentials()
{
//load model to query db
$this->load->model('membership_model');
$query = $this->membership_model->validate();
if($query){ //if credentials validated
$data = array(
'username' => $this->input->post('username'),
'is_logged_in' => true
);
$this ->session->set_userdata($data);
redirect('site/members_area');
}
else{ //if not validated load login form again.
$this->index();
}
}
}
Any idea what's going wrong? I should be going on to the 'members_area' page as I know the details I am entering are correct.
Any help would be much appreciated.
what is this??
/waitronmain/login.php/login/validate_credentials
login.php should be not in url i think you should do:
/waitronmain/login/validate_credentials
(assuming you removed index.php from urls and you are inside the waitronmain/ root )
wondering if anyone can guide me to what ive done wrong (or need to do) and think the problem is in my routes file. When the user is displayed the login form and for example they get their username wrong after submit the url displays as this: http://localhost:8888/codeigniter/login/login_validation. When the are successful and log into the admin area (which pulls news articles from the db) this url is still shown. I am wondering if there is a way to make it to http://localhost:8888/codeigniter/news. I have looked in my routes folder and i tried to use 'wildcards' and was unsuccessful. Here is my code for reference, any other info or files needed let me know! Thanks.
CONTROLLER:
class Login extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$this->load->view('login');
}
//Validate login area
public function login_validation() {
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|callback_username_check');
$this->form_validation->set_rules('password', 'Password', 'required|xss_clean|callback_password_check');
if($this->form_validation->run() == FALSE) {
//Field validation failed. User redirected to login page
$this->index();
}else{
$this->load->model('user_model');
$query = $this->user_model->login_details();
// if the user's credentials validated...
if($query) {
$data = array(
'username' => $this->input->post('username'),
'is_logged_in' => true
);
$this->session->set_userdata($data);
redirect('news');
}else{
$data['error'] ="Invalid Username or Password";
$this->load->view('login',$data);
}
}
}
function logout() {
$this->session->sess_destroy();
$this->index();
}
}
login_details function from user_model.php
function login_details() {
$this->db->where('username', $this->input->post('username'));
$this->db->where('password', md5($this->input->post('password')));
$query = $this->db->get('login');
if($query->num_rows == 1){
return true;
}
}
If you're logging into any kind of system, you're going to need to store a session using CodeIgniter's Session class. Provided controllers/news.php exists, you can set the session and immediately just perform a redirect with redirect('news');. No need to $this->load->view() because this logic will be in news.php's index anyway and you'd be duplicating code.
I'm not sure what $this->user_model->login_details() is returning, but I'm assuming false or null because you say CodeIgniter is sending you back to the login view. Head into the login_details() function and make sure things are working properly (you might want to post it too). Also, post your routes.php file for us if you made changes just in case.
On a side note: Space is a valid password character, don't trim it or folks with leading or trailing space's in their passwords won't be able to get in ;)
I have got my site(mysite.com) to redirect to mysite.com/Mobile for mobile browsers using codeigniters useragent library from my default controller.
When I cache my output from the controller the redirect doesnt work as the browser is served the cached file.
Is there a proper way to go about redirecting from the config/routes.php file? Will this redirect mobile visitors?
My controller
class Child extends Controller {
function child()
{
parent::Controller();
//$this->output->cache(7200);
$agent = $this->agent->browser() . ' ver ' . $this->agent->version();
}
function index()
{
if ($this->agent->is_mobile())
{
header('Location: ' . site_url() . 'Mobile/', TRUE, 301);
exit(0);
}else{
$this->output->cache(7200);
$this->load->view('home',$data);
}
}
I wouldn't suggest using CodeIgniter's output caching. That runs before the Controller, therefore you will never get in the index(). Routing can't deal with this situation as it isn't able to detect if the client is mobile.
It's a better idea to use the other caching method that CodeIgniter offers, as it's more granular, you can cache the single views. http://codeigniter.com/user_guide/libraries/caching.html
function index()
{
// should put this in the __construct() of this controller or in your MY_Controller.php
$this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));
if ($this->agent->is_mobile())
{
redirect('Mobile');
}
else
{
// if this doesn't get us the output, recreate and store it
if(!$output = $this->cache->get('controllername_index_output'))
{
$output = $this->load->view('home', $data, TRUE);
$this->cache->save('controllername_index_output', $output, 7200);
}
// now we surely have the output ready, whether it was cached or not
$this->output->set_output($output);
}
}