Zen Cart Logo
Forums / Managing Customers and Orders / Redirect after login/registration

Redirect after login/registration

Views: 4,763

Results 1 to 6 of 6
19 Aug 2011, 17:29
#1
mixtli avatar

mixtli

New Zenner

Join Date:
Jan 2011
Posts:
2
Plugin Contributions:
0

Redirect after login/registration

Hi guys, I have a slight problem with the redirect from the login page/registration, I'll explain: in my site use a lot of extra pages to present the products.

in these extra pages there is a button that leads to files that are in a folder in the root directory but that is not a zen cart folder.

I would that the user has logged in before accessing these files, so if the user click on the button to access these files without being logged in is redirected to the login page.

The ideal for me would be to redirect the user to these files after login (if coming from these extra pages), but I've seen is a bit 'problematic doing a redirect to non zen cart files and I would be fine also redirect the extra page of origin.

I made it in this way:

The extra page of origin sends the customer ID through get to the landing page (the non zen cart file) and in the landing page I entered:

if($_GET['customers_id']==''){
header('Location: http://www.mysite.com/index.php?main_page=login&page=page');
}

and it works, it will redirect to the login page if the user is not logged sending with get the variable "page"

then I inserted in the file includes/modules/page/login/header_php.php this code

if ($_GET['page']!='') {
  if ($origin_href != zen_href_link(FILENAME_DEFAULT)) {
    zen_redirect($origin_href);
  }
}
 

but it doesn't work, someone could help me?

Thanks to anyone who wants to answer

the version of zen cart is 1.3.9h

20 Aug 2011, 17:49
#2
mixtli avatar

mixtli

New Zenner

Join Date:
Jan 2011
Posts:
2
Plugin Contributions:
0

Re: Redirect after login/registration

Thanks, I solved it, just added ```
$_SESSION['navigation']->set_snapshot();

to includes/modules/pages/extrapage_I_want_to redirect_to/header_php.php.
as seen here <http://www.zen-cart.com/forum/showthread.php?t=37330>
forget the code above, there is no need to add anything else

thanks to DrByte :smile:
12 Oct 2015, 02:15
#3
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Redirect after login/registration

I realize I'm digging up an old thread, but it is obviously still relevant as I ran into the same issue with a fresh install. Previously I had my own contrib called SessionWatcher which did a couple of things, one of which was ensuring a user went back to the page they came from after logging in (something that just seems obvious to me from a UX point of view). I only recently upgraded to 1.5.4 and see that SessionWatcher doesn't work (no surprise). I set about updating it but then I realized this is a much easier way of achieving the same thing.

So... does anyone see any reason why we can't add something like this:

  if (!$_SESSION['customer_id']) {
    if (($_GET['main_page'] != FILENAME_LOGIN) && ($_GET['main_page'] != FILENAME_LOGOFF) && ($_GET['main_page'] != FILENAME_TIME_OUT) && ($_GET['main_page'] != FILENAME_CREATE_ACCOUNT_SUCCESS) && ($_GET['main_page'] != FILENAME_CREATE_ACCOUNT)) { 
      $_SESSION['navigation']->set_snapshot();
    }
  }

near the top of /includes/templates/MY_TEMPLATE/common/html_header.php?

It could be the very first line of PHP in that file, say directly above where you find:

require(DIR_WS_MODULES . zen_get_module_directory('meta_tags.php'));

I don't immediately see a problem and it certainly seems to work in my initial testing. But I'm open to suggestions. It probably shouldn't be done in a template file, but that seemed the easiest thing to do without monkeying around with files that are going to be destroyed in an update.

12 Oct 2015, 12:50
#4
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,065
Plugin Contributions:
56

Re: Redirect after login/registration

At a minimum, you'll want to add FILENAME_PAGE_NOT_FOUND to your list.

12 Oct 2015, 13:56
#5
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Redirect after login/registration

good call.

13 Oct 2015, 02:49
#6
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Redirect after login/registration

another one:

FILENAME_PASSWORD_FORGOTTEN

Just confusing when you get redirected there after logging in with a new password :)