Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Login Redirect to index instead of previous page


Guest

Recommended Posts

Hi,

 

I have looked through all contributions and searched this forum but cant find anything about it....

 

Basically, if you have a loginbox (infobox) and go to login, the loginbox form submits to login.php and then redirects to index.php instead of the last page you were on.

 

 

So to recap... if your on product_info.php looking at a product and then login via the loginbox, it redirects you to index.php instead of the product_info.php page you were on.

 

 

Anyone else noticed this? and what code do i edit from the login.php page to make it login to the page you were previous on?

 

  if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'process')) {
$email_address = tep_db_prepare_input($HTTP_POST_VARS['email_address']);
$password = tep_db_prepare_input($HTTP_POST_VARS['password']);

// Check if email exists
$check_customer_query = tep_db_query("select customers_id, customers_firstname, customers_password, customers_email_address, customers_default_address_id from " . TABLE_CUSTOMERS . " where customers_email_address = '" . tep_db_input($email_address) . "'");
if (!tep_db_num_rows($check_customer_query)) {
  $error = true;
} else {
  $check_customer = tep_db_fetch_array($check_customer_query);
// Check that password is good
  if (!tep_validate_password($password, $check_customer['customers_password'])) {
	$error = true;
  } else {
	if (SESSION_RECREATE == 'True') {
	  tep_session_recreate();
	}

	$check_country_query = tep_db_query("select entry_country_id, entry_zone_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$check_customer['customers_id'] . "' and address_book_id = '" . (int)$check_customer['customers_default_address_id'] . "'");
	$check_country = tep_db_fetch_array($check_country_query);

	$customer_id = $check_customer['customers_id'];
	$customer_default_address_id = $check_customer['customers_default_address_id'];
	$customer_first_name = $check_customer['customers_firstname'];
	$customer_country_id = $check_country['entry_country_id'];
	$customer_zone_id = $check_country['entry_zone_id'];
	tep_session_register('customer_id');
	tep_session_register('customer_default_address_id');
	tep_session_register('customer_first_name');
	tep_session_register('customer_country_id');
	tep_session_register('customer_zone_id');

	tep_db_query("update " . TABLE_CUSTOMERS_INFO . " set customers_info_date_of_last_logon = now(), customers_info_number_of_logons = customers_info_number_of_logons+1 where customers_info_id = '" . (int)$customer_id . "'");

// restore cart contents
	$cart->restore_contents();

	if (sizeof($navigation->snapshot) > 0) {
	  $origin_href = tep_href_link($navigation->snapshot['page'], tep_array_to_string($navigation->snapshot['get'], array(tep_session_name())), $navigation->snapshot['mode']);
	  $navigation->clear_snapshot();
	  tep_redirect($origin_href);
	} else {
	  tep_redirect(tep_href_link(FILENAME_DEFAULT));
	}
  }
}
 }

 

 

Thanks in advance to anyone that can answer and help!

Davey

Link to comment
Share on other sites

I've found it!

 

Basically this line needs to be added to the top of every page a customer can view (when not logged in)

 

$navigation->set_snapshot();

 

 

 

Then if they use the loginbox (infobox) they will be returned to the page they were previously viewing!

 

 

 

Davey.

Link to comment
Share on other sites

  • 2 months later...

I am having a Login.php looping issue, but it only happens when the log in page is access from the "write review" button clicked by a customer who is not logged in. When log in is submitted, the login page just refreshes over and over, but if you navigate to a product page, you are actually logged in.

 

Log in from the Index page works normal and the customer is redirected to Index.php as designed.

 

I am not getting any reviews because this is confusing customers, any ideas why the login is looping only when access from the write review button?

Link to comment
Share on other sites

[Customers stuck at loging page with redirected from the write write review page.]

 

I can see the code in login.php that sets the navigation and redirect, it appears ok.

 

The problem is that the login.php is looping to its self when the customer is directed to login when trying to write a review. When it loops, there is no indication that the customer is logged in although they are. I see customers get caught in this loop trap and leave without writing a review.

 

Ideas?

Link to comment
Share on other sites

  • 2 years later...
I've found it!

 

Basically this line needs to be added to the top of every page a customer can view (when not logged in)

 

$navigation->set_snapshot();

 

 

This didn't work for me - in the end I just hardcoded a change in login.php:

 

Around line 60 - find:

 

tep_redirect(tep_href_link(FILENAME_DEFAULT));

 

change to the following:

tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING));

 

You can chage the link to any file name you want to send your visitor to

Link to comment
Share on other sites

  • 2 months later...

why do you have to make it harder?

 

find the line //restore cart contents and make it look like this:

 

// restore cart contents

$cart->restore_contents();

echo "<script> history.go(-1); </script>";

die();

if (sizeof($navigation->snapshot) > 0) {

$origin_href = tep_href_link($navigation->snapshot['page'], tep_array_to_string($navigation->snapshot['get'], array(tep_session_name())), $navigation->snapshot['mode']);

$navigation->clear_snapshot();

tep_redirect($origin_href);

 

as you can see, just before OsC calls it's redirect function and after OsC verified the username and password, you do a history.go(-1), when customers login from login.php you may have to do a condition like:

 

if($_SERVER[HTTP_REFERER]==='login.php'):

echo "<script> history.go(-2); location.href='index.php'; </script>";

endif;

 

B)

Link to comment
Share on other sites

This didn't work for me - in the end I just hardcoded a change in login.php:

 

Around line 60 - find:

 

tep_redirect(tep_href_link(FILENAME_DEFAULT));

 

change to the following:

tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING));

 

You can chage the link to any file name you want to send your visitor to

 

 

Thanks ssnb - I had to do it this way. Couldn't get the other 2 ways to work. And, it is a perfectly fine landing page for any login, and it is the page you want whenever anyone has anything in their cart. Incidentally, this problem appeared after introducing SecurityPro -- I have no idea why login.php (even when I exclude it) shows this problem now. I'll have to go back and see if it is related to IP TRAP - the previous contribution i did.

Link to comment
Share on other sites

  • 2 weeks later...

I checked navigation_history.php; there is a function set_snapshot($page = '') ; looks each page will run this to save current pages information before run login page, but I am confused I can not find any session/cookie operation in this class, then when we run the "if (sizeof($navigation->snapshot) > 0) {" after success login, how can it get the the previous page information? I am quite confuse about it, is there any one do clear it for me?

Link to comment
Share on other sites

OK, I understand it now; The problem is when we run page login.php, system also change the previous page as login page in application_top.php; I did below change and find it works well in my site

 

find this in application_top.php

 

if (PHP_VERSION < 4) {

$broken_navigation = $navigation;

$navigation = new navigationHistory;

$navigation->unserialize($broken_navigation);

}

else {

$navigation = new navigationHistory;}

 

and replace with (only read color added)

 

if(basename($PHP_SELF)!=FILENAME_LOGIN){

if (PHP_VERSION < 4) {

$broken_navigation = $navigation;

$navigation = new navigationHistory;

$navigation->unserialize($broken_navigation);

}

else {

$navigation = new navigationHistory;}

}

Link to comment
Share on other sites

  • 5 months later...

Hi, all.

Try this.

under section

// restore cart contents

 

find the following line:

tep_redirect(tep_href_link(FILENAME_DEFAULT));

 

replace with:

 

echo "<script> history.go(-2); </script>";

 

that's it - should be working.

 

lzrczrs's method is even better:

go to your login.php file and change:

 

// restore cart contents

$cart->restore_contents();

if (sizeof($navigation->snapshot) > 0) {

$origin_href = tep_href_link($navigation->snapshot['page'], tep_array_to_string($navigation->snapshot['get'], array(tep_session_name())), $navigation->snapshot['mode']);

$navigation->clear_snapshot();

tep_redirect($origin_href);

 

to:

 

// restore cart contents

$cart->restore_contents();

echo "<script> history.go(-2); </script>";

die();

if (sizeof($navigation->snapshot) > 0) {

$origin_href = tep_href_link($navigation->snapshot['page'], tep_array_to_string($navigation->snapshot['get'], array(tep_session_name())), $navigation->snapshot['mode']);

$navigation->clear_snapshot();

tep_redirect($origin_href);

 

Thanks to lzrczrs.

Link to comment
Share on other sites

Thanks, kfang2004. This worked. The Best!

Just needed that blank space the first line of your code (right after 'if'):

 

if (basename($PHP_SELF)!=FILENAME_LOGIN){

if (PHP_VERSION < 4) {

$broken_navigation = $navigation;

$navigation = new navigationHistory;

$navigation->unserialize($broken_navigation);

}

else {

$navigation = new navigationHistory;}

}

Link to comment
Share on other sites

  • 3 weeks later...

Thanks, kfang2004. This worked. The Best!

 

I know this has nothing to do with login, but since a week, without doing anything when I visit the store and click any product or category, it only reloads the home index page ???

 

I noticed, when I reverse these settings to

Enable SEO URLs? false

Add cPath to product URLs? true

 

I get to see the path to the product/category

http://www.mystore.com/product_info.php?products_id=561 but after 2/3 seconds a 404

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

 

Anyone with an idea what this is caused by? (another store, exact the same setup on the same server, works without problems ... this is weird)

 

Thanks somuch

Link to comment
Share on other sites

  • 3 weeks later...
  • 4 weeks later...

Thanks, kfang2004. This worked. The Best!

Just needed that blank space the first line of your code (right after 'if'):

 

if (basename($PHP_SELF)!=FILENAME_LOGIN){

if (PHP_VERSION < 4) {

$broken_navigation = $navigation;

$navigation = new navigationHistory;

$navigation->unserialize($broken_navigation);

}

else {

$navigation = new navigationHistory;}

}

 

 

Thank you it worked well. I tried to solve this probleem for 3 hours!

Link to comment
Share on other sites

Hi, the redirect works amazing but I have a strange issue.

I installed the anti robot registration (http://www.oscommerce.com/community/contributions,1237) and when a user adds a product to the cart, goes to check out, then logs in with their existing user name and pass it redirects to the image png on

the validation_png.php.

 

Does anyone have the same contribution installed or any help on the issue?

 

I have the same issue with the redirect / login contribution.

 

Thanks for everything!

Mike

Link to comment
Share on other sites

  • 2 months later...

Thank you it worked well. I tried to solve this probleem for 3 hours!

 

same for me. this fix is working well for me.

 

concerning the contribution Contrib Login and Return to the same page, this contrib has many bugs and must be fixed including the code added by kfang2004 here.

 

i had the same analysis, somehow the navigation->snapshot value became emptied on getting on login.php, thus the returning page was lost.

 

thanks kfang2004!!!!

Link to comment
Share on other sites

after some search, the problem came back with the create_account.php and create_account_success.php

so kfang2004 fix is working only on returning customers. you might have same problems with new customers.

so it is not the real fix to this issue!

 

the real problem comes from an old fix, see this issue with the following post, which is related to the navigation history:

 

http://www.oscommerce.com/forums/topic/346007-first-post-here-please-help-me/page__gopid__1512238entry1512238

 

the real fix should be:

this code (above) is wrong, you should use:

// navigation history
if (tep_session_is_registered('navigation')) {
  if (PHP_VERSION < 4) {
 $broken_navigation = $navigation;
 $navigation = new navigationHistory;
 $navigation->unserialize($broken_navigation);
  } elseif (!is_object($navigation)) {
 $navigation = new navigationHistory;
  }
} else {
  tep_session_register('navigation');
  $navigation = new navigationHistory;
}
$navigation->add_current_page();

Link to comment
Share on other sites

  • 1 month later...

after some search, the problem came back with the create_account.php and create_account_success.php

so kfang2004 fix is working only on returning customers. you might have same problems with new customers.

so it is not the real fix to this issue!

 

the real problem comes from an old fix, see this issue with the following post, which is related to the navigation history:

 

http://www.oscommerce.com/forums/topic/346007-first-post-here-please-help-me/page__gopid__1512238entry1512238

 

the real fix should be:

 

Thanks Demoalt, we've been struggling with this broken navigation issue for a long time and the suggestion you suggested worked brilliantly!

Most Valuable OsCommerce Contributions:

Also Purchased (AP) Preselection (cuts this resource hogging query down to nothing) -- Contribution 3294

FedEx Automated Labels -- Contribution 2244

RMA Returns system -- Contribution 1136

Sort Products By Dropdown -- Contribution 4312

Ultimate SEO URLs -- Contribution 2823

Credit Class & Gift Voucher -- Contribution 282

Cross-Sell -- Contribution 5347

Link to comment
Share on other sites

  • 9 months later...

I tried all the options and none work as needed.

 

Problems:

 

1 - the client is identified with nothing in the car... why you have to show the empty car? why not go to the front of the store?

 

2 - the client is identified having items in the cart... because he has to send the cover of the tent? why not go on the buying process?

 

Solution:

 

Open catalog/login.php

 

Find:

 

// restore cart contents
       $cart->restore_contents();

       if (sizeof($navigation->snapshot) > 0) {
         $origin_href = tep_href_link($navigation->snapshot['page'], tep_array_to_string($navigation->snapshot['get'], array(tep_session_name())), $navigation->snapshot['mode']);
         $navigation->clear_snapshot();
         tep_redirect($origin_href);
       } else {
         tep_redirect(tep_href_link(FILENAME_DEFAULT));
       }

 

 

Replace:

 

// restore cart contents
       $cart->restore_contents();

       if (sizeof($navigation->snapshot) > 0) {
         $origin_href = tep_href_link($navigation->snapshot['page'], tep_array_to_string($navigation->snapshot['get'], array(tep_session_name())), $navigation->snapshot['mode']);
         $navigation->clear_snapshot();
         tep_redirect($origin_href);
       } elseif (!$cart->count_contents() > 0) {
         tep_redirect(tep_href_link(FILENAME_DEFAULT));
       } else {
         tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING));
       }

 

This sends the customer to the front of the store if you have nothing in the car when it is identified, or is sent to the buying process if you have a product in the cart.

 

Sorry for my bad English.

Link to comment
Share on other sites

  • 8 months later...

what happened when the custumer add goods to his shopping cart and the system tell him that he has to create an account if he does not nave one alrready.

 

?

 

The system lead him to index after create the account instead to teh checkout process.

 

how can be led to his shopping cart directly instead index and/or the worst case create_account_success.php ???

Link to comment
Share on other sites

what happened when the custumer add goods to his shopping cart and the system tell him that he has to create an account if he does not nave one alrready.

 

?

 

The system lead him to index after create the account instead to teh checkout process.

 

how can be led to his shopping cart directly instead index and/or the worst case create_account_success.php ???

 

By default, oscommerce will return the customer back to the last page viewed after creating an account. The posts in this thread discuss how to change that function but generally NO changes are needed.

 

 

 

Chris

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...