Quick Authentication

Posted by Brian Moon 
Re: Quick Authentication
May 22, 2006 04:56PM
What else does the USER array contain? Can it check whether user is an admin?
Re: Quick Authentication
May 22, 2006 06:54PM
In that case, the "admin" field would be 1. What you can do is print out the contents of the user to see what's in it. The following code would give you a readable print-out:
print "<pre>";
print_r($USER);
print "</pre>";


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Quick Authentication
June 03, 2006 08:32AM
I would like to redirect user to homepage after login if the user first came from the homepage otherwise to thread list.
e.g
my forum located in example.com/forum and the rest of the pages located in example.com. so if the user came from example.com I want to redirect user to example.com, if the user came from example.com/music.php to redirect example.com/music.php and lastly if the user came from forum thread to redirect that particular forum thread.

any help how to do it?
thanks in advance.
Re: Quick Authentication
October 23, 2006 09:17AM
Thank you for posting quick_auth-5.1.php Thomas, it works well with 5.1.16a

/\dam

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
Re: Quick Authentication
November 28, 2006 03:36AM
I may have spoken too quickly. I'm using quick_auth-5.1.php and I think it is picking up custom profile fields from the old serialised user_data field.
Shouldn't it be accessing the phorum_user_custom_fields table instead?

Thanks,

/\dam

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
Re: Quick Authentication
November 28, 2006 04:03AM
Here is a new version that reads from the 5.1x phorum_user_custom_fields table.
I'd appreciated some core Phorum coders checking that I'm doing this in the right way.

<?php
// quick_auth.php by Brian Moon
// once this script is in place, you will have a $USER variable
// that you can use anywhere you want.
/* eg:
	if($USER["user_id"]){
	    echo "logged into Phorum";
	} else {
	    // echo "logged out";
	}
*/

if(isset($_COOKIE["phorum_session_v5"])){

    if(isset($PHORUM["user"])){

        $GLOBALS["USER"] = $PHORUM["user"];

    } else {

        define("PHORUM", "quick_auth");

        // wrap all this in a function to protect it and other code
        function check_session()
        {
            // one of these needs to be commented out.
            $require = "cookie_sessid_lt";  // long term cookie that will exist over time
            //$require = "sessid_st"; // short term cookie that may not be required at all, but is more secure

            include_once($_SERVER["DOCUMENT_ROOT"]."/phorum/include/db/config.php");

            list( $user_id, $sess_id ) = explode( ":", $_COOKIE["phorum_session_v5"], 2 );

            $user = urldecode($user);

            if(get_magic_quotes_gpc()){
                $user=stripslashes($user);
                $md5pass=stripslashes($md5pass);
            }

            $conn=mysql_connect($PHORUM["DBCONFIG"]["server"], $PHORUM["DBCONFIG"]["user"], $PHORUM["DBCONFIG"]["password"], true);
            mysql_select_db($PHORUM["DBCONFIG"]["name"], $conn);

            $sql="select * from ".$PHORUM["DBCONFIG"]["table_prefix"]."_users where user_id='".mysql_escape_string($user_id)."' and $require='".mysql_escape_string($sess_id)."'";

            $res=mysql_query($sql, $conn);

            if(mysql_num_rows($res)){
                $USER=mysql_fetch_assoc($res);

                // first get names of profile fields from phorum_settings table
                $sql="select `data` from ".$PHORUM["DBCONFIG"]["table_prefix"]."_settings WHERE `name` = 'PROFILE_FIELDS'";
                $res=mysql_query($sql, $conn);
                $row = mysql_fetch_array($res);
                $profile_field_names = unserialize($row["data"]);

                // now get custom profile fields from phorum_user_custom_fields table
                $sql="select * from ".$PHORUM["DBCONFIG"]["table_prefix"]."_user_custom_fields where user_id='".mysql_escape_string($user_id)."'";
                $res=mysql_query($sql, $conn);
                if(mysql_num_rows($res)){
                	while ($row = mysql_fetch_array($res)){
                		$thistype = $row["type"];
                		$thisdata = $row["data"];
                		$thisfield = $profile_field_names[(int)$thistype]["name"];
                		$USER[$thisfield]=$thisdata;
                	}
                }
            } else {
                $USER=array();
            }

            $GLOBALS["USER"]=$USER;

        }
        check_session();
    }
}
?>

Thanks,

/\dam

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
Re: Quick Authentication
December 01, 2006 03:41PM
Thanks Brian.
Maybe you could rename your version to 5.2 though so new users know which one to grab?

/\dam

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
Re: Quick Authentication
December 01, 2006 04:26PM
The version is for the phorum-version it is for and its probably not for phorum 5.2 ;).


Thomas Seifert
Re: Quick Authentication
December 01, 2006 08:02PM
Ah, I see - sorry, being dense :-)

/\

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
Re: Quick Authentication
December 04, 2006 10:26AM
Great script Brian, just what I was looking for to give registered users on my forum benefits elsewhere on my site,

thanks

Mark
Sorry, only registered users may post in this forum.

Click here to login