FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum » How To » fudapi login with out redirect
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
fudapi login with out redirect [message #35127] Sun, 10 December 2006 23:46 Go to next message
bleak26 is currently offline  bleak26   United Kingdom
Messages: 7
Registered: December 2006
Karma: 0
Junior Member
Is it possible to login using the external_fud_login, but with out it redirecting? is the redirecting important ? i wish to remove redirection ,so that i can use external_fud_login without disturbing my login process.

Also please could you tell me in which file i can find the redirect that takes place during the login using external_fud_login and if possible (cheeky) the line name or function name.


one last last thing. WOW THE API IS EXCELENT, WELL DONE. its the first time i have attempted anything like this in intergration terms and it has been much eaiser than any of the alternatives. also the fudforum support forum looks as though people actauly get help, which was the other element which helped me decide to use the forum.

Thank you
Re: fudapi login with out redirect [message #35130 is a reply to message #35127] Mon, 11 December 2006 05:12 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
The api does not actually do any redirects, it only generates a "logged in" session id which it returns and sets a cookie for the user.

FUDforum Core Developer
Re: fudapi login with out redirect [message #35454 is a reply to message #35127] Fri, 12 January 2007 15:26 Go to previous messageGo to next message
maarten is currently offline  maarten   United States
Messages: 7
Registered: January 2007
Karma: 0
Junior Member
I think I'm having a similar problem, so I'll post in this thread.

I wanted to get the current login status to use in an external app, and added this function to fudapi.inc.php:

 function fud_get_current_uid()
 {
 	fud_use('cookies.inc');
 	fud_use('users.inc');

 	return _uid;
 }


The page that uses this works OK, but when it's used on a page with a form, and the form is submitted, it ends up redirecting to the forum index page. I haven't dug deep enough yet to figure out why.

So...
- any thoughts on why this might happen?
- should I be obtaining the current UID in a different way?

Thanks!

Maarten.

[I'm writing an alternate Drupal integration module since the existing one doesn't do what I'm looking for.]
Re: fudapi login with out redirect [message #35458 is a reply to message #35454] Fri, 12 January 2007 17:54 Go to previous messageGo to next message
maarten is currently offline  maarten   United States
Messages: 7
Registered: January 2007
Karma: 0
Junior Member
What was happening was that users.inc called user_init, which called sq_check(), which caused a "Header:" redirect.

I replaced my code with this:

        fud_use('cookies.inc');

        if (!($u = ses_get())) {
                return 0;
        } else {
                return $u->id;
        }


which seems to work fine; pls let me know if there's a better way to get the current UID from an external script.

Maarten.
Re: fudapi login with out redirect [message #35465 is a reply to message #35458] Sun, 14 January 2007 17:08 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
You shouldn't do this like this. I would suggest reading the session id from the FUDforum cookie, who's name is found in GLOBALS.php (already pre-loaded by FUDPAI) and then running the query on the FUDForum's session table.

FUDforum Core Developer
Re: fudapi login with out redirect [message #35476 is a reply to message #35465] Mon, 15 January 2007 17:41 Go to previous messageGo to next message
maarten is currently offline  maarten   United States
Messages: 7
Registered: January 2007
Karma: 0
Junior Member
Alright, changed to so:

function fud_get_current_uid()
 {
	$sess_id = $_COOKIE[$GLOBALS['COOKIE_NAME']];

	if (empty($sess_id)) {
		return 0;
	}

	$q_str  =
		'SELECT user_id'
		. ' FROM '       . $GLOBALS['DBHOST_TBL_PREFIX']. 'ses'
		. ' WHERE ses_id=' . _esc($sess_id);

	$id = q_singleval($q_str);
	if (null === $id || 2000000000 <= $id) {
		return 0;
	}
	return $id;
}


Edit: Modified to filter out userids of anonymous users. Those will show up as not logged in.

[Updated on: Mon, 15 January 2007 19:58]

Report message to a moderator

Odp: Re: fudapi login with out redirect [message #35956 is a reply to message #35476] Fri, 23 February 2007 14:00 Go to previous message
Janek is currently offline  Janek   Poland
Messages: 1
Registered: November 2006
Location: Warsaw, Poland
Karma: 0
Junior Member
You can also try this one:
<?
function external_fud_get_current_user_id() {
    
    __fud_login_common(1);
    
    $ses_id = $_COOKIE[$GLOBALS['COOKIE_NAME']];
    if(!empty($ses_id) && strlen($ses_id)==32) {
        $sys_id = __ses_make_sysid(($GLOBALS['FUD_OPT_2'] & 256), ($GLOBALS['FUD_OPT_3'] & 16));
        $r = q_singleval("SELECT user_id FROM ".$GLOBALS['DBHOST_TBL_PREFIX']."ses WHERE ses_id="._esc($ses_id)." AND sys_id="._esc($sys_id)." AND user_id<2000000000");
        return $r?$r:0;
    } 
    return 0;
}
?>

It's more safe, as it also checks sys_id.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: make the grid lines turn black
Next Topic: Moderators issues
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Dec 04 19:50:44 GMT 2024

Total time taken to generate the page: 0.02049 seconds