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!

BoomBoomBap 11-12-2003 11:18 PM

Seems like a pretty cool mod but regardless of which incarnation of it I use it only gets redirected to a blank page. The page source is cart.php?mode=auth but it is blank.

Im using Netscape 7.1 and Xcart 3.4.9

carlisleglass 11-18-2003 04:36 AM

looks like you missed a } on the end of that coding ...

This is the revised coding ...
Quote:

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");
            }
        }



Tried it in 3.4.9 and works.

BoomBoomBap 11-28-2003 04:08 PM

Looks like I got this working with Hair Guy's code.
Here's what Im using for 3.4.10

Code:

# new login mod
$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
                                func_header_location("../$redirect/cart.php?mode=checkout");
                        } elseif (preg_match($mysite_pattern, $_SERVER['HTTP_REFERER'])) {
                                # go back to where we were before login
                                func_header_location(" ".$_SERVER['HTTP_REFERER']);
                        } else {
                                func_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>If you see this message it means that your browser doesn't support Javascript or it is disabled. Please enable JavaScript in your browser settings for proper X-Cart functionality.";
                        x_session_save();
                        exit;
                }
                else {
                        if (preg_match($mysite_pattern, $_SERVER['HTTP_REFERER'])) {
                                # go back to where we were before login
                                func_header_location(" ".$_SERVER['HTTP_REFERER']);
                        } else {
                                func_header_location("../$redirect/home.php");
                        }
                }
        }
# here ends new login mod


PhilJ 01-24-2004 10:01 AM

Great Mod, ought to be standard in X-Cart, but has anyone updated this for v3.5.x ?

PhilJ

xcell67 05-09-2004 06:30 PM

Quote:

+++++++++++++++++++++++++++++++++++++++++++++
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;
}




There is a slight problem with this.
Example:

The customer tries logging in either through the side panel login box or the center login box but enters a wrong password or wrong username. The incorrect password/username message will show up, and then they enter the correct details and log in. The problem is that the incorrect password/username message will still show, and it might confuse some customers who will wonder why that message is still there if they just logged in correctly.

How would you apply an exception to the code so that if the customer is logging in after an unsuccesful attempt, that it would either redirect them back to page they were at before or back to the home page.

jeremye 05-10-2004 02:05 AM

I ran into the same issue, and I just added an exception for the page "error_message.php?login_incorrect", as follows (this is my entire code snippet:

Code:

                if ($login_type=="C") {
                        /* If the cart has items in it, redirect them to their cart */
                        if(!func_is_cart_empty($cart)) {
                                func_header_location("../$redirect/cart.php");
                        }
                        /* Otherwise, find what page they were at and send them there */
                        else {
                                $relo_page = strrchr($_SERVER['HTTP_REFERER'], '/');
                                $relo_page = str_replace('/', '', $relo_page);
                                /* Unless they were on the "Login" individual page */
                                if ($relo_page == "error_message.php?login_incorrect")
                                        $relo_page = "home.php";
                                func_header_location("../$redirect/$relo_page");
                        }
                }


Hope this helps.

xcell67 05-23-2004 11:23 PM

Hi, question about your login form solution
 
Hi,
Thank you for your modification, I was able to integrate it succesfully:

"I ran into the same issue, and I just added an exception for the page "error_message.php?login_incorrect", as follows (this is my entire code snippet: "

Code:

      if ($login_type=="C") {
        /* If the cart has items in it, redirect them to their cart */
        if(!func_is_cart_empty($cart)) {
            func_header_location("../$redirect/cart.php");
        }
        /* Otherwise, find what page they were at and send them there */
        else {
            $relo_page = strrchr($_SERVER['HTTP_REFERER'], '/');
            $relo_page = str_replace('/', '', $relo_page);
            /* Unless they were on the "Login" individual page */
            if ($relo_page == "error_message.php?login_incorrect")
              $relo_page = "home.php";
            func_header_location("../$redirect/$relo_page");
        }
      }



What I have been having trouble with is integrating the checkout bit that was also in the same post. Were you able to get the correct code so that the customer would be redirected to step 2 if they signed in the middle of the checkout process?

By the way,

this bit for the above code also redirects them to home if they mistype their login/pw 3 times and are given the recover password screen:

if ($relo_page == "error_message.php?login_incorrect" OR "help.php?section=Password_Recovery")

Thanks,
James

arabayaservis.com 05-26-2004 02:24 AM

for 3.5.7

if customer directory different name
codes must be :

Code:

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


laureon 05-29-2004 06:30 AM

Hi,

I have recently begun a fresh install of v3.5.8. I don't know if it's just me, but when I modify login.php to redirect to the referring page, the cart still redirects to either home.php or the cart. I have deleted all cached templates etc. but am still having no luck. Is anyone else experiencing a similar problem?

P.S - I have had the code working successfully in v3.5.7

thanks

xcell67 06-04-2004 11:59 PM

what would be the correct code if you had moved the contents from /customer into the root of your site? I did this so the site could be accessed by shop.com/home.php instead of shop.com/customer/home.php

I'm currently using this code:
Code:

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


The redirect for the cart.php works but the redirect for the relopage does not. It redirects to my index.html rather than home.php.

cotc2001 10-22-2004 12:47 PM

Anyone got a update to this code for 4.0.x(5) ????

g0t0pless 10-22-2004 09:50 PM

4.0.5 already does this, at least on my installation it does. It looks like X-Cart took your idea, and implemented it into the new version.

balinor 12-16-2004 06:55 AM

Anyone get this to work with 3.5.12 or .13?


All times are GMT -8. The time now is 08:02 AM.

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