CodeIgniter Forums
Redirect to the same page? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Redirect to the same page? (/showthread.php?tid=34634)



Redirect to the same page? - El Forum - 10-05-2010

[eluser]victorche[/eluser]
Basically the title says it all. I have a login form in the header and now I am using:
Code:
redirect('/', 'refresh');
Is there a simple way to redirect the user after form submit to the same page?
For example, if they are logging from the faq page, the redirect to be to /faq

Thanks in advance!


Redirect to the same page? - El Forum - 10-05-2010

[eluser]John_Betong[/eluser]
Immediately before your redirect statement, take a look at your server setting which should show where the user was before arriving at your function.

Code:
echo '<pre>';
  print_r($_SERVER);
echo '</pre>';
&nbsp;
&nbsp;
&nbsp;


Redirect to the same page? - El Forum - 10-05-2010

[eluser]danmontgomery[/eluser]
Generally you'll want to save the current url in the session before redirecting to the login page, then after a successful login, check for that value and redirect there or to a default page if it isn't present.


Redirect to the same page? - El Forum - 10-05-2010

[eluser]John_Betong[/eluser]
&nbsp;

Here is the code to redirect users back to where they were. (It allows users to see the page they were viewing in a different colour).

Code:
...
  ...
  ...
  // refresh the REFERRING page    
  $url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : base_url();
  $url = empty($url) ? base_url() : $url;

  redirect($url, 'refresh');

}//endfunc