Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

use login box and retain current location


Guest

Recommended Posts

I installed the loginbox contribution (is there anyone here who hasn't?!), and would like o do the following:

at the moment, when a customer logs in, he's redirected to the index page, regardless of where he was. Is there a way to remember where he was, and keep him there after the login? I have searched the forums for this matter and found nothing. I think this is very important, because if a customer is about to purchase something, he may decide to give up if he will have to start looking for it again, simply because he logged in...

 

-Ethan

Link to comment
Share on other sites

I found that the redirecting is caused by the following linews, taken from login.php:

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

        }

 

So the question now is, what has to be changed in order for it to redirect back to the previous page, when logging in from the login box? I tried commenting out the IF statement, and got an error saying that the server doesn't know to where it should redirect me..

I'm sure this isn't too dificult to acheive, and would really help a lot of folks...

 

-Ethan

Link to comment
Share on other sites

have you found the answer to your question? I really need the answer to this too but i don't have nearly enough PHP knowledge to figure it out. I found a couple of other posts like this one, but they weren't answered either :( .

Link to comment
Share on other sites

This forum isn't as responsive as it was in the past...
I am afraid this is true and it is very sad indeed :(

 

I don't understand what this is about:

          $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);

but there is a $_SERVER['REQUEST_URI'] variable (not available on al servers I believe) wich contains the needed info

 

Also found something on php.net which solves the problem if you don't have $_SERVER['REQUEST_URI'] available.

 

 

This is the easiest way to get a $_SERVER['REQUEST_URI'] when it's not available:

<?php
  if (!isset($_SERVER['REQUEST_URI'])) {
      $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'];
  }
?>

 

I hope we can implement this (without introducing errors :) ) somehow.

Link to comment
Share on other sites

Sorry, I was probably missing the point, the $navigation array probably already contains or should/could contain the needed info (no need to use $_SERVER['REQUEST_URI'] ).

 

Hmm.. afraid this does not help much, <_<

Link to comment
Share on other sites

ok...try this:

 

replace

 

tep_redirect(tep_href_link(FILENAME_DEFAULT));

 

with

 

tep_redirect($_SERVER[HTTP_REFERER]);

 

it's working on my site, but i haven't tested it on other computer or in different browsers yet.

Link to comment
Share on other sites

Hi Sandra,

 

it seems that it does not always work, wich might be better than never of course :)

'HTTP_REFERER'

    The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted

 

Also I wonder if it's always the reffering page is what you want show, would you have an url so we can test it? (you can PM it if you don't want it posted on the board)

Link to comment
Share on other sites

sure...here you go: My Webpage

 

(please excuse the mess...it's still a major work in progress :lol: )

 

use the email address [email protected] and the password 12345.

this function worked for me here and for my husband at work on both IE and Mozilla. That doesn't necessarily mean much except at least it's working in those locations :). I found the same info that you posted when i did the search, but i figured it was worth the try. I would be interested in knowing what happens when it fails, so if anyone tries and it fails, please let me know! I know NOTHING about PHP, but this was driving me nuts and i needed to find a fix LOL. oh, and my login is in the header instead of in a login box, so i don't know if that would affect anything or not.

Link to comment
Share on other sites

Hi Sandra,

please excuse the mess...it's still a major work in progress
it isn't ready but it certainly looks promising :)

 

I did some testing, it seems to work very nice exept for one thing:

 

If you use the normal login.php page to login (for example because you typed a wrong password at first), then after the login it seems like the login did not work because you are sent back to the login.php page (even the login error stays if the password was wrong the first time). So the login did work, but the costumer might think it didn't.

 

As far as I can see now this is the only case that you don't want to go back to the referring page.

 

We can insert an if statement, so that if the referring page is the login page itself you are sent to the index after all.

 

Paul

Link to comment
Share on other sites

We can insert an if statement, so that if the referring page is the login page itself you are sent to the index after all.

here is my first attempt, not tested yet but it might work:

        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 {
         if (strrchr((basename($_SERVER[HTTP_REFERER])), FILENAME_LOGIN ))
         { // if the referring page is login.php => show index page after login
           tep_redirect(tep_href_link(FILENAME_DEFAULT));
         }
         else
         { // if the referring page is not login.php => show previous page after login
           tep_redirect($_SERVER[HTTP_REFERER]);
         }
       }

the way it is checked if the referring page is login.php might not be the smartest way to do it, but that's all I can think of now

 

or the changed part only is:

         if (strrchr((basename($_SERVER[HTTP_REFERER])), FILENAME_LOGIN ))
        { // if the referring page is login.php => show index page after login
          tep_redirect(tep_href_link(FILENAME_DEFAULT));
        }
        else
        { // if the referring page is not login.php => show previous page after login
          tep_redirect($_SERVER[HTTP_REFERER]);
        }

 

If you try it please tell me how it works, I would like to use it myself too but I don't have time to test it right now.

 

hth

Paul

Link to comment
Share on other sites

it's back to reverting to the index page when you log in.
strange, when I test it on my local machine it does seem to work ok :unsure:

 

Just to be sure I post what I exactly did,

In login.php (approx. line 65) replaced:

        } else {
         tep_redirect(tep_href_link(FILENAME_DEFAULT));
       }

by:

        } else {
       //  tep_redirect(tep_href_link(FILENAME_DEFAULT));
         if (strrchr((basename($_SERVER[HTTP_REFERER])), FILENAME_LOGIN ))
         { // if the referring page is login.php => show index page after login
           tep_redirect(tep_href_link(FILENAME_DEFAULT));
         }
         else
         { // if the referring page is not login.php => show previous page after login
           tep_redirect($_SERVER[HTTP_REFERER]);
         }
       }

At my local server a login through the loginbox returns to the page where you were before the login. And a login at login.php redirects to the index.php page (i.s.o. back to the login.php page).

 

I decided to take the risc and installed it on my live shop (while writing this post :) ), I will PM the link (since I rather don't have too many fake orders/accounts).

Link to comment
Share on other sites

Hi Sandra, thanks very much for testing too.

 

It looks like you are using MS1 (i.s.o. MS2), maybe it has something to do with that, allthough I can't imagine what. You could also try to leave out "basename" (you can leave the brackets where they are, doesn't matter if you have extra bracktets) it should work without it too.

 

hth

Paul

Link to comment
Share on other sites

yeah...i am running MS1...i couldn't get MS2 to work on my host when i set it up and i was too overwhelmed at the time to try to figure it out. Now I just don't feel like doing my mods again. I'll try what you said :).

Link to comment
Share on other sites

I found that the redirecting is caused by the following linews, taken from login.php:

 

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

        }

 

 

So the question now is, what has to be changed in order for it to redirect back to the previous page, when logging in from the login box? I tried commenting out the IF statement, and got an error saying that the server doesn't know to where it should redirect me..

 

I think if you add the following lines of code to any file that you want to be remembered,

then the code in login.php will take you back to the page (i.e., set the snapshot on

the pages where they must be logged in so that the code in login.php will take them

back to it):

  if (!tep_session_is_registered('customer_id')) {

    $navigation->set_snapshot();

    tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));

  }

 

Hope that helps and hope it didn't add confusion.

Link to comment
Share on other sites

i'm not sure i really understand those instructions or how they would work. where would i put that info?

 

unfortunately, removing basename didn't work for me either.

 

another idea i thought of was to somehow indicate the login error in (or under since mine is in the header) the login box and have them try to login again right there instead redirecting to the login page at all. then the page wouldn't be an issue at all since there are no links to it on my site (or if they are, i'll take care of them :P) and i could just use the HTTP_REFERRER solution.

 

for now, i've just taken an easy, though not great, way out. I created a "login successful" page with the following text on it:

 

"Please hit the Back button on your browser to return to the product screen you were visiting, or click on one of the catagories to the left. If you logged in from the login screen, you may have to hit your back button twice. Click the button below to return to the home page."

 

It's not ideal, but it will do for now since I can't seem to get anything else working :( . I may revisit it later, but I'm spending too much time on a seemingly easy issue :lol: . I've got bigger fish to fry...like how to get my gift vouchers working correctly :huh: .

 

thanks for all your help and i'm certainly open to any suggestions :). If nothing else, maybe the info posted will help someone else!

Link to comment
Share on other sites

Hi Sandra,

 

are you really sure you didn't make any mistake? Did you for example comment out the original code like this "// tep_redirect(tep_href_link(FILENAME_DEFAULT));"?

 

I have been thinking about this some more and I really can't imagine why it shouldn't work the same for your MS1 shop as for my MS2 shop. Especially because the "tep_redirect($_SERVER[HTTP_REFERER]);" does work on your shop too. The other lines are just a simple if statement and string check to see if the REFERER filename happens to be login.php itself or not (or to be more precise it checks if the REFERER filname string contains the string "login.php" (<=FILENAME_LOGIN)).

Link to comment
Share on other sites

Hi Sandra,

 

I think I know the difference now between your site and mine, and it might lead to the solution, not sure yet.

My shop is at the webroot and yours is not (it's in the subdir catalog).

 

Hope to do some testing soon, the solution would involve using $_SERVER['REQUEST_URI'] (in case you or anyony else wan't to try something).

 

If someone else also has tried the "$_SERVER[HTTP_REFERER] solution" posted in this thread, could you please confirm that it does or does not work and if your shop is at the webroot?

Link to comment
Share on other sites

thanks so much for the work you have put into this...it's definitely beyond me
Sorry the $_SERVER['REQUEST_URI'] idea probably was nonsense.

You pointed me to the $_SERVER[HTTP_REFERER] solution, so we've helped each other :) and I just like to experiment with things like this.

 

Only problem is, I'm afraid it's beyond me now too :( .

Link to comment
Share on other sites

yeah...i did too, and i was pretty proud of myself for getting even that far considering i have no idea what i am doing :lol: .

 

for now, i think the solution i'm using will work. I may end up moving the store to my root, and if i do, i'll give the solution another shot.

 

thanks again :).

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...