Don’t you hate it when you make a promise and then forget or almost forget to deliver as expected? Someone in the forums was having a problem with the X-Cart Login Redirect for certain templates. I told them I could help as it would be a relatively easy mod, then the week just blew up on me.
Everything that could happen this week did happen this week. From Client fires, to even someone running from the cops and wrecking their car in my front yard at 3 am. Talk about adventures.
Anyway, the problem occurs on any template that came with X-Cart which didn’t have the login form built in on every page. What happens is that after visiting the login page and successfully logging in it wouldn’t redirect back to the original page you came from. Instead you would just end up back on the home page.
At first look this appears to be just the “Light and Lucid (2 Column)” and the “Vivid Dreams” templates.
All the other templates have a login form on every page, and when a visitor successfully logs in, they are redirected to that page. But these other templates had a special login page for lack of room. I guess since most templates have the login form on every page they can easily redirect back to the page you entered your login details, but they just forgot about the other pages. How considerate of them
So the process is pretty simple to fix. And this fix should be on the mark for X-Cart 4.3.x by the way, and should work for other templates that use the login page.
Open /error_message.php and look for line 56 or so, you should see something like this:
} elseif($error == "permission_denied") {
func_403($id, true);
}
#
# Assign login information
#
And we are going to change it to look like this:
} elseif($error == "permission_denied") {
func_403($id, true);
## If login page is loaded store the referer but ONLY if from this site
} elseif($error == "need_login") {
if (strpos($_SERVER['HTTP_REFERER'],$xcart_http_host)) {
$check_referer = $_SERVER['HTTP_REFERER'];
$smarty->assign("check_referer", $check_referer);
}
}
if ($referred && strpos($referred,$xcart_http_host)) {
$check_referer = $referred;
$smarty->assign("check_referer", $check_referer);
}
#
# Assign login information
#
Moving on, next open /include/login.php and find line 45 or so, you should see this:
define('AREA_TYPE', $_GET['usertype']);
}
require $xcart_dir."/init.php";
And let’s change that to:
define('AREA_TYPE', $_GET['usertype']);
}
if (!empty($_POST['referred'])) {
$check_referer = $_POST['referred'];
}
require $xcart_dir."/init.php";
In that same file, drop down to line 350 or so, and you should find:
$redirect_url = $redirect_to.strrchr(func_qs_remove($HTTP_REFERER, $XCART_SESSION_NAME), "/"); } } if (!$redirect_url) $redirect_url = $redirect_to."/home.php"; }
And let’s change that to look like:
$redirect_url = $redirect_to.strrchr(func_qs_remove($HTTP_REFERER, $XCART_SESSION_NAME), "/"); } } if ($check_referer && !$redirect_url) $redirect_url = $check_referer; if (!$redirect_url) $redirect_url = $redirect_to."/home.php"; }
Okay the last file, open /skin1/customer/main/login_form.tpl, and find line 10, you’ll find:
<input name="mode" type="hidden" value="login" />
Directly below that, add the following:
{if $check_referer}
<input name="referred" type="hidden" value="{$check_referer|escape}" />
{/if}
There we have it, should be all done now. It works in my development environments, if you find something not working please shoot me an email with as much information as possible so I can fix it and adjust. If you need help getting this installed, feel free to contact me.
One very very last note:
If you are running the secure login form with X-Cart
Open /secure_login.php and around line 48 add:
## If login page is loaded store the referer but ONLY if from this site
if (strpos($_SERVER['HTTP_REFERER'],$xcart_http_host)) {
$check_referer = $_SERVER['HTTP_REFERER'];
$smarty->assign("check_referer", $check_referer);
}






7:02 pm
OMG you are a genius man!!!!
Its working perfectly!!!!
I love you!!
11:34 am
Glad you like it. Since you posted this another site found a few bugs in regards to logging into the checkout and it not redirecting properly, as well as it didn’t remember the redirect properly if you typed the wrong password the first time. I’ve fixed both bugs and the new code is above, please reapply.
11:10 am
I want make the “include/login.php” check the protocol if it is not equal to https.
make it return the page with https.we used x-card 4.2.2 version.
how much and how to pay to you.
your best freind:
andy
11:15 am
Just a heads-up: This will not work on X-Cart 4.4.3, as the files have been changed drastically. A new approach is needed.