Welcome Guest, Not a member yet? Register   Sign In
Button to fetch user back to their previous URL instead of clicking on the browser Back button
#1

[eluser]tkaw220[/eluser]
Hi,

I would like to implement a "continue shopping button" on shopping cart page to return customer to their previous URL. Any idea how I could achieve this? Using session? cookie? How?

Thanks for the help.
#2

[eluser]jgetner[/eluser]
i would figure to use the cache class... just cache the page then once they decide to return to where they where before just call that cached page.
#3

[eluser]tkaw220[/eluser]
Hi jgetner,

Do you have any sample code using the CI cache class? I am not familiar with that class. Any reference would be great.

Billion thanks. Have a nice day.
#4

[eluser]WanWizard[/eluser]
Save $_SERVER['HTTP_REFERER'] in the session when a user requests the cart contents or presses on "checkout".

When the "continue shopping" button is pressed, check if you have this session variable, and if so, if it's a URL from your site (to prevent redirects to other sites), and if so, redirect() to it.
#5

[eluser]InsiteFX[/eluser]
Code:
if (isset($this->input->server('HTTP_REFERER')))
{
    $this->session->set_userdata('prev_url', $this->input->server('HTTP_REFERER'));
}
else
{
    $this->session->set_userdata('prev_url', base_url());
}

// when Continue Shopping button clicked.
redirect($this->session->userdata('prev_url'), 'location');

InsiteFX
#6

[eluser]WanWizard[/eluser]
To make sure you're storing a URL from your site:
Code:
if (isset($this->input->server('HTTP_REFERER')) && strpos($this->input->server('HTTP_REFERER'), base_url()) === 0)
{
    ....
}
#7

[eluser]InsiteFX[/eluser]
Thanks WanWizard, I'll have to add that to method.

I have a snippits library saves on typing all the time LOL.

InsiteFX
#8

[eluser]tkaw220[/eluser]
Many thanks to both of you. Now I have a working function to redirect customers back to their previous location. Again, thank you.

Cheers,
Edwin
#9

[eluser]InsiteFX[/eluser]
tkaw220, Make sure you change my if statement to the way WanWizard stated, I have already updated my code for the change.

InsiteFX
#10

[eluser]WanWizard[/eluser]
[quote author="InsiteFX" date="1300726399"]I have a snippits library saves on typing all the time LOL.[/quote]
Not a bad idea, I've noticed I have to copy&paste; to much... Wink




Theme © iAndrew 2016 - Forum software by © MyBB