Get previous url and use it as back button in codeigniter

I am really wondering how I can do this, I have 3 pages with the same link as 1 page, now what I want to do is to have 1 button which is smart enough to get. which of the three pages was used to navigate to this page and use it as it links to the previous page.

Please, if anyone knows how to do this, help me get out into this chaos. post some code how to do this in codeigniter. Thank you in advance.

+3


source to share


3 answers


Using simple javascript to achieve the previous button like



<a href="javascript:window.history.go(-1);">Previous</a>

      

+5


source


With url helper loaded , set current_url in a hidden field, say 'refer_from'.

<input type="hidden" name="refer_from" value="<?php echo current_url(); ?>" />

      

Get this using Input Class and set this on a binding



<a href="<?php echo $this->input->post('refer_from'); ?>">Previous</a>

      

NOTE: using window.history.go (-1) will fail and throw a js error if the user is somehow directly on the last page "1". window.history will be empty in this case.

+4


source


In my case, the return methods in jquery mean window.history and so on don't work, so I tried this hope it will help you guys. This method can be clicked. greetings

  function redirection()
        {
           <?php $send=$_SERVER['HTTP_REFERER'];?> 
            var redirect_to="<?php echo $send;?>";             
            window.location = redirect_to;

        }

      

0


source







All Articles