Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Login Form Modification

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 04-22-2003, 02:30 PM
 
machnhed1 machnhed1 is offline
 

eXpert
  
Join Date: Feb 2003
Location: Illinois
Posts: 274
 

Default 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
__________________
Following the signature guidelines : xcart pro 3.5.8 - [RedHat]
Reply With Quote
  #2  
Old 04-30-2003, 08:44 AM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default

You rule. I'll be adding these mods to my site soon.
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.
Reply With Quote
  #3  
Old 04-30-2003, 08:50 AM
 
machnhed1 machnhed1 is offline
 

eXpert
  
Join Date: Feb 2003
Location: Illinois
Posts: 274
 

Default

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.
__________________
Following the signature guidelines : xcart pro 3.5.8 - [RedHat]
Reply With Quote
  #4  
Old 04-30-2003, 09:02 AM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default

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.
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.
Reply With Quote
  #5  
Old 04-30-2003, 01:38 PM
  shan's Avatar 
shan shan is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Birmingham, UK
Posts: 6,163
 

Default

Yeh, this is a great little mod.

This should be added to xcart as standard i think.

Why not send this one to xcart
__________________
Looking for a reliable X-cart host ?
You wont go wrong with either of these.

EWD Hosting
Hands On Hosting
Reply With Quote
  #6  
Old 05-02-2003, 04:51 PM
 
Hair Guy Hair Guy is offline
 

Newbie
  
Join Date: May 2003
Posts: 3
 

Default 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"); } }
Reply With Quote
  #7  
Old 05-07-2003, 07:24 AM
 
mnrrcom mnrrcom is offline
 

Advanced Member
  
Join Date: Apr 2003
Posts: 41
 

Default v3.3.5

How do I prevent anonymous checkout?
Reply With Quote
  #8  
Old 05-07-2003, 12:35 PM
  groovico's Avatar 
groovico groovico is offline
 

X-Man
  
Join Date: Apr 2003
Location: Firetanksoftware.com
Posts: 2,326
 

Default

Nice one! I was just about to start hacking x-cart to bits to do exactly this! Ta dude.
Reply With Quote
  #9  
Old 08-25-2003, 01:48 PM
 
luizgg luizgg is offline
 

Newbie
  
Join Date: May 2003
Posts: 8
 

Default

Any idea how to make this work on 3.4.x?
Thanks.
Reply With Quote
  #10  
Old 10-25-2003, 09:10 AM
 
shasan shasan is offline
 

Advanced Member
  
Join Date: Oct 2003
Location: Toronto
Posts: 74
 

Default

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 I loved that!
__________________
X-Cart 3.4.2 - Processor: Dual Hamsters, running on tricked out 21\" version of Hamster Wheel. (tireless little buggers)

No hamsters were harmed during the making of this sig. Several were seriously offended.
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 09:06 PM.

   

 
X-Cart forums © 2001-2020