News:

Wondering if this will always be free?  See why free is better.

Main Menu

How to keep on same page after Login

Started by danwsc, March 10, 2012, 12:18:44 AM

Previous topic - Next topic

danwsc

Hi,

I am currently writing an android application that uses SimpleMachines forum to implement one of its functions.
In the mobile application, the SimpleMachines forum is accessed at a particular modified page.
This page also has a Login form however whether the Login is successful or not,
the browser gets redirected to the SimpleMachines forum main page.
How can I keep the browser on the same page whatever the outcome of the Login please.

Regards.

emanuele

You can define the page SMF will redirect after the login by assigning the variable $_SESSION[login_url'], you can see something similar in SSI at the function ssi_login (I think...).


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

danwsc

Hi emanuele,

That seems to work if the login is successful
But if the login is unsuccessful, it still reverts to the SMF page..
How do I keep it on the same page even if the login is unsuccessful or if the user does not enter a name or password?

Thanks and Regards.

emanuele

Ah ok, I see: try to set also $_SESSION['old_url'], then it should do what you want...I think.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

danwsc

Sorry, setting

$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];

doesn't work. :(
I tried it right after u told me what to do for the $_SESSION['login_url']

Thanks and Regards.

distante

I'm not quite sure if android works like a regular browser, but take a look to the parse of my mod http://custom.simplemachines.org/mods/index.php?mod=2714

I'm using HTTP REFERRER, for what you want, but in a regular site.

emanuele

Quote from: danwsc on March 11, 2012, 09:22:32 AM
Sorry, setting

$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];

doesn't work. :(
I tried it right after u told me what to do for the $_SESSION['login_url']
You should set $_SESSION['old_url'] only "outside" the login page, instead if the only place you can set it is in the login page itself, then you should set it to $_SERVER['HTTP_REFERER'] as suggested by distante and only ONCE, so something like:
if (!isset($_SESSION['old_url']))
$_SESSION['old_url'] = $_SERVER['HTTP_REFERER'];


but then doing it with login_url would be the same. ;)
Last note, if you use this approach just after the login is successful you should unset $_SESSION['old_url'] or $_SESSION['login_url'] depending on the one you used.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

danwsc

#7
Hi,

Currently I am putting my program in a file, sayit.php whose path is public_html/sayit/radio/sayit.php
This program is serviced by my version of SSI.php called mySSI.php whose path is public_html/sayit/mySSI.php

The login/logout page is in sayit.php
serviced by mySSI_login in mySSI.php which paints the login box (same as SSI_login but without the openid section
and the user/password textboxes & button horizontal)

I am currently setting $_SESSION['login_url'] from sayit.php, where it works.
I tried setting $_SESSION['old_url'] here too but that didn't work.
I tried updating LogInOut.php as what distante did in RememberPositionV1.3.1 (many thanks distante!)
but this did not appear to work either.

One thing I realized about the Login2 code is that if u leave the username box empty, the program returns at

   // You forgot to type your username, dummy!
   if (!isset($_POST['user']) || $_POST['user'] == '')
   {
      $context['login_errors'] = array($txt['need_username']);
      return;
   }

This bypasses all the code modifications in RememberPositionV1.3.1 because those only come in play when
sa=check is set and this in turn only occurs after a successful Login.

When login fails, which part of the code generates the SMF header page with Login template please?



Biology Forums

My forum does this automatically.

By any chance, have you edited subs.php file lately?

danwsc

Hi Liam,

No I haven't edited Subs.php.
My application devotes a single link for each BB topic,
so whether the user is logged in or not, that BB topic must be shown.

Hence I don't want to redirect away form the initial page and
I don't want any of index.template.php or login.template.php or
anything that usually shows up on a PC based screen.

A further problem is that the SMF forum should function normally if accessed outside my App.

AFAIK, in a normal SMF forum, if u hit the Login button without putting anything in username,
u will get another login form which is displayed within the normal SMF background.

Regards.

danwsc

Okay I think I've got it at least preliminary testing seems to be okay.
I will summarize it here for posterity :)

to stay on the same page requires 3 types of modifications

1.  Login, use provided redirect for ssi_login
2.  Logout, use provided redirect for ssi_logout

3.  The only thing left is unsuccessful logins (maybe SMF can consider this sometime).
There are two parts to this problem
a. SMF loads different templates / sub-templates to prepare the browser screen for display.
These have to be disabled or rather, I provided an alternative so that if my application is detected,
it would do something more appropriate for my application (e.g. donothing)
b. unsuccessful login's are detected at several positions within Login2() and then returned to the
calling function.  Instead of a straight forward return, I conditionally diverted the return so that
if the application is detected, it would redirect to the URL I wanted.

I am going to keep this thread open for a while so that if I did something dumb, somebody can tell me.
Thanks to all who have helped me.

Thanks and Regards.

Advertisement: