0

I'm New to CI and MVC. I wanted to know how i can redirect to base_url(); when the user reloads (by pressing F5 or by clicking on reload button)

Steps done so far:- I came across this post in tutorials plane http://tutorialsplane.com/codeigniter-redirect-refresh/

I have used the code given in the post redirect(base_url(),"refresh");, but what this does is to redirect to base_url(); no matter what.

I'm wondering what is wrong here, can someone please guide me through???

Rohit Nair
  • 628
  • 3
  • 7
  • 22

2 Answers2

0

Not sure if this will work but it may.

session_start()
if($_session["page"] != basename($_SERVER['PHP_SELF']) || !isset($_session["page"]))
    $_session["page"] = basename($_SERVER['PHP_SELF']); 
}else{
    //reload has been done
}

So if session variable is not set or not the same as current filename then it will update the session variable.
Then the else is something you need to fill in.
You need to add this code to all your pages

EDIT see now that you use CodeIgniter. Don't know if you can use this then.

Andreas
  • 23,610
  • 6
  • 30
  • 62
0

codeigniter redirect() does not detect for a refresh. the option you are using is for a type of redirection.

look at this for examples to catch a refresh. put one of these detections into your controller methods or __construct if it applies to all methods, then use redirect if the refresh was detected.

eg from the link by 'Gideon Rosenthal';

$pageWasRefreshed = isset($_SERVER['HTTP_CACHE_CONTROL']) && $_SERVER['HTTP_CACHE_CONTROL'] === 'max-age=0';
if($pageWasRefreshed ) {
   //do something because page was refreshed;
} else {
   //do nothing;
}

theres a comment that this method may have its limits.

many others

here and here

js detection is easy to insert and dont need to be CI aware to redirect.

Community
  • 1
  • 1
2114L3
  • 564
  • 5
  • 8