Codeigniter | Get previous URL and used as back button to previous page

I really wonder how can I do this, I have 3 pages that has the same link going to 1 page, now what I want to do is to have 1 button that is intelligently enough to get which of the 3 pages was used to go to that page and used it as it's link going back to that previous page.

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


By using a simple javascript to achieve previous button like,

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

With the url helper loaded, set the 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 the anchor link

<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 some how lands directly on the "1" last page. window.history will be empty in that case.