Jump to content


Corporate Sponsors


Latest News: (loading..)

- - - - -

Login Redirect to index instead of previous page


24 replies to this topic

#1 davestacey

  • Community Member
  • 96 posts
  • Real Name:Dave
  • Gender:Male
  • Location:England

Posted 20 November 2006, 14:56

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

#2 davestacey

  • Community Member
  • 96 posts
  • Real Name:Dave
  • Gender:Male
  • Location:England

Posted 20 November 2006, 15:11

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.

#3 digipete

  • Community Member
  • 132 posts
  • Real Name:Pete Quintanilla
  • Gender:Male
  • Location:La Mesa, California

Posted 20 November 2006, 16:39

Dave,

What line number would that go in?


Pete

#4 davestacey

  • Community Member
  • 96 posts
  • Real Name:Dave
  • Gender:Male
  • Location:England

Posted 20 November 2006, 21:51

I just put it at the top after the <?php and it worked.

#5 mmph

  • Community Member
  • 121 posts
  • Real Name:Mark
  • Location:Washington - USA

Posted 18 February 2007, 08:27

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?

#6 mmph

  • Community Member
  • 121 posts
  • Real Name:Mark
  • Location:Washington - USA

Posted 21 February 2007, 06:32

[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?

#7 ssnb

  • Community Member
  • 278 posts
  • Real Name:Sol
  • Gender:Male
  • Location:Auckland, New Zealand

Posted 18 April 2009, 00:35

View Postdavestacey, on Nov 20 2006, 03:11 PM, said:

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

#8 lzrczrs

  • Community Member
  • 10 posts
  • Real Name:eliezer cazares
  • Gender:Male
  • Location:Monterrey

Posted 29 June 2009, 20:36

why do you have to make it harder?

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

Quote

// 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:

Quote

if($_SERVER[HTTP_REFERER]==='login.php'):
echo "<script> history.go(-2); location.href='index.php'; </script>";
endif;

B)

#9 gates2u

  • Community Member
  • 17 posts
  • Real Name:Cheryl Campbell

Posted 04 July 2009, 17:49

View Postssnb, on Apr 17 2009, 08:35 PM, said:

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.

Edited by gates2u, 04 July 2009, 17:50.


#10 kfang2004

  • Community Member
  • 3 posts
  • Real Name:King Fang

Posted 17 July 2009, 16:54

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?

#11 kfang2004

  • Community Member
  • 3 posts
  • Real Name:King Fang

Posted 17 July 2009, 18:54

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

#12 stevenbrown

  • Community Member
  • 4 posts
  • Real Name:Stephen Brown

Posted 10 January 2010, 14:05

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.

#13 stevenbrown

  • Community Member
  • 4 posts
  • Real Name:Stephen Brown

Posted 11 January 2010, 02:03

View Poststevenbrown, on 10 January 2010, 14:05, said:

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.

#14 stevenbrown

  • Community Member
  • 4 posts
  • Real Name:Stephen Brown

Posted 11 January 2010, 03:19

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

Edited by stevenbrown, 11 January 2010, 03:20.


#15 cb21

  • Community Member
  • 14 posts
  • Real Name:Norbert Harms

Posted 28 January 2010, 01:22

View Poststevenbrown, on 11 January 2010, 03:19, said:

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

#16 gijsve

  • Community Member
  • 15 posts
  • Real Name:Gijs van Egmond

Posted 13 February 2010, 20:53

There is a contribution for this subject called Login and Return to same page.

http://www.oscommerce.com/community/contributions,3129

#17 cb21

  • Community Member
  • 14 posts
  • Real Name:Norbert Harms

Posted 14 February 2010, 17:06

View Postgijsve, on 13 February 2010, 20:53, said:

There is a contribution for this subject called Login and Return to same page.

http://www.oscommerce.com/community/contributions,3129

WOW
osCommerce ... A truly amazing piece!

Not sure what stupidity of mine got me here but surely I'm not that stupid to stay with it!

#18 cemrotterdam

  • Community Member
  • 3 posts
  • Real Name:CEM YILDIRIM

Posted 13 March 2010, 12:24

View Poststevenbrown, on 11 January 2010, 03:19, said:

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!

#19 mikenew

  • Community Member
  • 20 posts
  • Real Name:No

Posted 17 March 2010, 03:05

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

#20 demoalt

  • Community Member
  • 15 posts
  • Real Name:Demoalt

Posted 31 May 2010, 16:16

View Postcemrotterdam, on 13 March 2010, 12:24, said:

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!!!!