Post by el3ati2 » Thu Jan 23, 2014 5:21 am

I am adding a login box when a user hovers over "login" in the welcome message.
I know there are a few extensions out there (and some are free), but I'm working on my own.
I need your help to figure out how to redirect the browser to the page I am currently at, after a I hit the "login" submit button.
In other words I want to browser to return to the page from which I logged in.
I know I should modify the login.php controller, and change the redirect line, but I'm not sure how to point to the url from which I am opening the login popup.

Any assistance is appreciated.. thanks
Last edited by el3ati2 on Thu Jan 23, 2014 8:21 pm, edited 1 time in total.

Newbie

Posts

Joined
Thu Nov 28, 2013 9:25 am

Post by tacobandito » Thu Jan 23, 2014 10:18 am

If I were you, I would do it by passing the current URL in as a GET variable.

Something along the lines of

Code: Select all

<?php 
$thisPage = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
?>
then just add the variable to the url like so....

Code: Select all

<a href="http://demo.opencart.com/index.php?route=account/login&thisPage=<?php echo $thisPage; ?>">login</a>
then receive the variable in your script like so...

Code: Select all

 <?php 
$thisPage = $_GET['thisPage'];
?>
and from there you should be able to handle it, as at that point you have the original url as a variable.

Alternatively, you could use javascript

Code: Select all

history.go(-1)
Enjoy :)

[module] PayPal Pro w/Recurring Profiles FREE
[module] 1 Click "Amazon Style" Checkout w/PayPal Pro FREE
[module] Adjustable PayPal Pro Fee FREE
[module] Add Sample To Cart LITE FREE
The guide to fixing just about everything wrong with OpenCart FREE!
Add INFINITE SCROLL to your homepage for FREE!
Live update product price for FREE!
Dynamic generation of Opencart coupon, FREE!
Hire me


User avatar
Active Member

Posts

Joined
Sat Mar 30, 2013 12:27 am
Location - Springfield, MA

Post by el3ati2 » Thu Jan 23, 2014 8:21 pm

Thank you for replying.

I tried your method but there's something wrong with it.

I inserted the following in login.tpl:

Code: Select all

<?php 
$thisPage = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
?>
it is therefore included in the new div that is created when I hover over "login" in the welcome message.

But since the above code resides in login.tpl, SERVER[REQUEST_URI] returns the login page address instead of the page from where I created the new div.

The solution for that is to replace the above code with:

Code: Select all

<?php 
$thisPage = $_SERVER[HTTP_REFERER];
?>
This does exactly what I need it to.
Anyway, thanks for putting me on the right track!

Cheers

Newbie

Posts

Joined
Thu Nov 28, 2013 9:25 am

Post by ogun » Thu Jan 23, 2014 9:28 pm

Not sure that HTTP_REFERER can be trusted. You might be better off/safer finding out the URL of the page and feeding it to your login template.

If you have a search, there are a few threads that discuss saving the current page URL to the session or making it a template variable (either one of those would be a nice feature for OpenCart to have if it doesn't already). E.g. http://forum.opencart.com/viewtopic.php?f=4&t=1164

Active Member

Posts

Joined
Tue Aug 14, 2007 6:04 am

Post by el3ati2 » Fri Jan 24, 2014 4:33 am

I have wrapped the redirect statement with an IF/ELSE statement that makes sure the HTTP_REFERER is set and that it points to one of my websites pages (other than the logout page because that would cause it to logout right after logging in). In this way I can make sure it is doing exactly what I need it to.

I've checked the alternative method of creating a session variable, but since I'm a PHP beginner and the above method seemed easier to implement and since it is performing the required task, I've gone through with it.

Anyway thanks for your reply.

Newbie

Posts

Joined
Thu Nov 28, 2013 9:25 am
Who is online

Users browsing this forum: No registered users and 8 guests