X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Login Form Modification (https://forum.x-cart.com/showthread.php?t=2404)

machnhed1 04-22-2003 02:30 PM

Login Form Modification
 
I hate the fact that x-cart takes you back to the home page if you log into the site without anything in your cart. Here's the mod that will take you back to the page you just came from when you log in.

+++++++++++++++++++++++++++++++++++++++++++++
This modification will take you back to the page you came from unless you have something in your cart. In the latter case, it will take you to your shopping cart.
+++++++++++++++++++++++++++++++++++++++++++++
Original File: login.php
Code:

                if ($login_type=="C") {
                        if(!func_is_cart_empty($cart))
                                header("Location: ../$redirect/cart.php");
                        else
                                header("Location: ../$redirect/home.php");
                        exit;
                }

Modified File: login.php
Code:

                if ($login_type=="C") {
                        if(!func_is_cart_empty($cart))
                                header("Location: ../$redirect/cart.php");
                        else {
                                $relo_page = strrchr($_SERVER['HTTP_REFERER'], '/');
                                $relo_page = str_replace('/', '', $relo_page);
                                header("Location: ../$redirect/$relo_page");
                                }
                        exit;
                }



+++++++++++++++++++++++++++++++++++++++++++++
This modification will allow you to control which pages redirect you back to shopping cart, which redirect you back to the homepage and which you want redirected back to the page they came from. Simply adjust the order to suit your priorities and add &locator=1 to any page's url that you would like the user to be redirected to once they log in. You can also add as many &locator=#'s to the if statement and move people all around the site :)
+++++++++++++++++++++++++++++++++++++++++++++
Original File: login.php
Code:

                if ($login_type=="C") {
                        if(!func_is_cart_empty($cart))
                                header("Location: ../$redirect/cart.php");
                        else
                                header("Location: ../$redirect/home.php");
                        exit;
                }

Modified File: login.php
Code:

                                if ($login_type=="C") {
                        if (strstr($_SERVER['HTTP_REFERER'], 'locator=1')){
                                $relo_page = strrchr($_SERVER['HTTP_REFERER'], '/');
                                $relo_page = str_replace('/', '', $relo_page);
                                header("Location: ../$redirect/$relo_page");
                                }
                        elseif(!func_is_cart_empty($cart))
                                header("Location: ../$redirect/cart.php");
                        else
                                header("Location: ../$redirect/home.php");
                        exit;
                }


+++++++++++++++++++++++++++++++++++++++++++++
And finally...
This modification is the same as the first one, but will also recognize if your user is logging in while in the middle of the checkout process of the shopping cart and will redirect them to the next step in the checkout process rather than taking them back to step one.
+++++++++++++++++++++++++++++++++++++++++++++
Original File: login.php
Code:

                if ($login_type=="C") {
                        if(!func_is_cart_empty($cart))
                                header("Location: ../$redirect/cart.php");
                        else
                                header("Location: ../$redirect/home.php");
                        exit;
                }

Modified File: login.php
Code:

                                if ($login_type=="C") {
                        if (strstr($_SERVER['HTTP_REFERER'], 'cart.php?mode=auth')){
                    header("Location: ../$redirect/cart.php?mode=checkout");
            }
                        elseif(!func_is_cart_empty($cart))
                                header("Location: ../$redirect/cart.php");
                        else {
                                $mover = strrchr($_SERVER['HTTP_REFERER'], '/');
                                $mover = str_replace('/', '', $mover);
                                header("Location: ../$redirect/$mover");
                                }
                        exit;
                }


I have been adding to this message as I have been coding so it's kind or a patchwork of stuff, hope no one gets confused :!:

minorgod 04-30-2003 08:44 AM

You rule. I'll be adding these mods to my site soon.

machnhed1 04-30-2003 08:50 AM

Finally a response!!!

I'm glad someone likes these; I thought they were going to be a hit. They ended up being another Apple Newton. :lol:

minorgod 04-30-2003 09:02 AM

Man, I'm just impressed that you managed to untangle the login code enough to write this script. I've managed to tweak myself into a corner with respect to this. I had my DigitalSubscription module working perfectly in the old 3.1.3a version of x-cart and then upgraded and tried to re-modify the new version (3.3.1) and now all my customers have to create a login/password or the user's info is lost when they try to check out, until they fill in a username/password. I've got logic to check the cart contents and if they have any DigitalSubscripton products then we can't allow anonymous checkout. My code is now preventing ALL anonymous checkouts instead of just the one's containing DigitalSubscriptions (which they'll need a username and password to access). Not sure why yet, but I'd be interested to know how you approached your project above. Maybe I'm missing something that would make x-cart easier to understand? I understand all the languages (PHP,Smarty,JavaScript, etc) but when they're all working together on the same page, it gets very hard to follow.

shan 04-30-2003 01:38 PM

Yeh, this is a great little mod.

This should be added to xcart as standard i think.

Why not send this one to xcart

Hair Guy 05-02-2003 04:51 PM

Improved version
 
I took your code and made a few minor improvements. Using HTTP_REFERER is not foolproof, since it is set by the browser. So my code goes back to the original behavior if the REFERER is not set. Also, this code is for version 3.3.4 and handles checkout logins from both the "Click to login" link and from the regular login box (normally on the right-hand side).

Code:

                $mysite_pattern = '~^(http://'.$xcart_http_host.'|https://'.$xcart_https_host.')~';
                if($login_type=="C" && !func_is_cart_empty($cart)) {
                        if (preg_match('/\/cart\.php\?mode=(auth|checkout)/', $_SERVER['HTTP_REFERER'])) {
                                # go to next step in checkout
                                header("Location: ../$redirect/cart.php?mode=checkout");
                        } elseif (preg_match($mysite_pattern, $_SERVER['HTTP_REFERER'])) {
                                # go back to where we were before login
                                header("Location: ".$_SERVER['HTTP_REFERER']);
                        } else {
                                header("Location: ../$redirect/cart.php");
                        }
                } elseif ( ($config["General"]["default_pwd"]=="Y") and (count($default_accounts)>0) and $admin_safe_mode==false) {
                        echo"<SCRIPT language='JavaScript'>
                        alert('Default passwords for one or more administrator/provider accounts are not changed. We recommend you to change default passwords for security reasons. The default X-cart accounts$default_accounts_string!');   
                        self.location='$to_url';
                        </SCRIPT>      ";
                }
                else {
                        if (preg_match($mysite_pattern, $_SERVER['HTTP_REFERER'])) {
                                # go back to where we were before login
                                header("Location: ".$_SERVER['HTTP_REFERER']);
                        } else {
                                header("Location: ../$redirect/home.php");
                        }
                }


mnrrcom 05-07-2003 07:24 AM

v3.3.5
 
How do I prevent anonymous checkout?

groovico 05-07-2003 12:35 PM

Nice one! I was just about to start hacking x-cart to bits to do exactly this! :) Ta dude.

luizgg 08-25-2003 01:48 PM

Any idea how to make this work on 3.4.x?
Thanks.

shasan 10-25-2003 09:10 AM

I tried it on 3.4.2 and the problem was that you filled out the form, and hit login, but it didn't log you in for some reason.

Now I'm not a programmer, but I did really well on pattern detection in an IQ test, so I think I have a fix :) It seems to work fine, the problem was with the following call to header function:

Code:

header("Location: ../$redirect/cart.php");

In my version, the original login.php used the format:

Code:

func_header_location("../$redirect/cart.php");

There are two instances in the mod snippet that require changing, but that's all and it seems to work like a charm :)

So in the 3.4.2 version, the mod will be as follows:

Original File: login.php (line 125)
Code:

if ($login_type=="C") {
                        if(!func_is_cart_empty($cart))
                                func_header_location("../$redirect/cart.php");
                        else
                                func_header_location("../$redirect/home.php");
                }


Modified File: login.php

Code:

if ($login_type=="C") {
        if(!func_is_cart_empty($cart))
            func_header_location("../$redirect/cart.php");
        else {
            $relo_page = strrchr($_SERVER['HTTP_REFERER'], '/');
            $relo_page = str_replace('/', '', $relo_page);
            func_header_location("../$redirect/$relo_page");
            }


HTH, lemme know if it works for you.

P.S. This works even if the customer is registering during checkout, and redirects them back to the page they were on, so they don't have to hit 'checkout' again :D I loved that!


All times are GMT -8. The time now is 05:29 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.