Welcome Guest, Not a member yet? Register   Sign In
redirect and come back of my navigator
#1

[eluser]MrAmine[/eluser]
hello everyone
I create a small login form and for the moment it works well
I have a small problem with the helper redirect
when I login and I click on button (come back) my browser back to the login page with the form even if I have write the condition
if(isset($session)){
redirect('homepage');
}
it works when I click on F5 (REFRECH)
#2

[eluser]InsiteFX[/eluser]
That's because your web browser is caching your web pages!
Code:
redirect('homepage', 'refresh');

InsiteFX
#3

[eluser]MrAmine[/eluser]
still the same problem
my code
if(isset($session)){
redirect('home','refresh');
}

Sad
#4

[eluser]InsiteFX[/eluser]
You can try this, not tested! You need to call the before displaying you view file!
Code:
$this->output->set_header("HTTP/1.0 200 OK");
$this->output->set_header("HTTP/1.1 200 OK");
$this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
$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");
$this->output->set_header("Cache-Control: post-check=0, pre-check=0");
$this->output->set_header("Pragma: no-cache");

InsiteFX
#5

[eluser]MrAmine[/eluser]
or I must write this code?
before the code of my view ?
thx
#6

[eluser]toopay[/eluser]
Why you write it '$session' not '$_SESSION'?
What if you do that in CI spec, something like...
Code:
....
// in login function
function login($username,$password)
{
   // do some authentification
   ....
   ....
   ....
   // if passed, set the session userdata
   $this->session->set_userdata('login', TRUE);
}
....
// then in home page function
function home()
{
   if($this->session->userdata('login') == TRUE){
   redirect('homepage');
}
#7

[eluser]MrAmine[/eluser]
yes but the problem when i clic on back button of firefox i come back to login form
#8

[eluser]toopay[/eluser]
lol. of course you will! Its because it the browser fetch the page from its cache, without interacting with the server at all.
#9

[eluser]MrAmine[/eluser]
what is the solution
#10

[eluser]InsiteFX[/eluser]
Ok, so now you are saying that you are clicking on the back buttom which means your browser is using the history cache!

You need to set your pages to use a no cache header! Here is a quick way to try out but it doe's not work in all broswers.

Add this to your head section in your html page:
Code:
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
?>

<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</head>

// Fix for IE Browsers add this after your </body> tag!
</body>
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</head>
</html>

This is because IE Broswers will not see the first one!

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB