how can a page redirect users back to previous page if they try to access the page via url?

笑着哭i 提交于 2019-12-04 05:47:12

In the page that you want to go back to you can do:

$this->session->set_userdata('referred_from', current_url());

Then redirect back to that page

$referred_from = $this->session->userdata('referred_from');
redirect($referred_from, 'refresh');

Try this :

$this->load->library('user_agent'); redirect($this->agent->referrer());

else

Use SESSION for login and logout. if session exist block login page else allow login page using if statement.

I'm doing this way.

redirect($_SERVER['HTTP_REFERER']);

I don't know if there is any better way, but i always do this:

When user is on About page and clicks on login, take the about page url address, do maybe base64_encode on it and then send it to login page via GET as a parameter. On login page, if credentials are valid, you take that parameter from GET, base64_decode and redirect there.

If you are doing that only for main pages, you can get only the controller from the url, but if you want to apply it on every page (/controller/method/var1/var2) then take the entire URL or entire url minus base url.

Let me know if this tip helped.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!