Quick Authentication
Posted by Brian Moon
Re: Quick Authentication March 15, 2009 02:56PM |
Registered: 16 years ago Posts: 34 |
March 15, 2009 03:13PM |
Admin Registered: 20 years ago Posts: 8,532 |
As you can read in the script itself, the user data is stored in the global variable $USER. The fields that are in that variable can easily be dumped on the screen by using a bit of code like:
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
Language: PHPprint "<xmp>"; print_r($GLOBALS[';USER';]); print "</xmp>"; // or what will most probably work too: print "<xmp>"; print_r($USER); print "</xmp>";
Maurice Makaay
Phorum Development Team



Re: Quick Authentication March 15, 2009 03:25PM |
Registered: 16 years ago Posts: 34 |
Yeah, I tried that, but it doesn't work...
The file has been included successfully, I tried that by having an echo "a"; in the quick_auth-5.2.php.
But the arry is not defined.
I get
Do you have any idea what the mistake could be?
Thanks!
Edited 1 time(s). Last edit at 03/15/2009 03:26PM by munich.
The file has been included successfully, I tried that by having an echo "a"; in the quick_auth-5.2.php.
But the arry is not defined.
I get
when I used the first code you posted.Language: HTML<br /> <b>Notice</b>: Undefined index: USER in <b>/....php</b> on line <b>90</b><br />
Do you have any idea what the mistake could be?
Thanks!
Edited 1 time(s). Last edit at 03/15/2009 03:26PM by munich.
March 15, 2009 06:52PM |
Admin Registered: 20 years ago Posts: 8,532 |
Well, that result would be a sign that the script did not find a logged in Phorum user. So you are either nog logged in or the script does not have access to the Phorum authentication cookie. No access to the cookie could have various reasons:
It's hard to tell what the exact problem is for you. You'll have to do some more debugging on the code. Focus on the cookie retrieval for starters. When a Phorum cookie is available, the rest should be a breeze.
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
- You are accessing the forum on a different domain / hostname than the main site;
- Phorum is inside a subdirectory and the cookie path in the general settings was changed to reflect that;
- Other reasons that I didn't think of.
It's hard to tell what the exact problem is for you. You'll have to do some more debugging on the code. Focus on the cookie retrieval for starters. When a Phorum cookie is available, the rest should be a breeze.
Maurice Makaay
Phorum Development Team



Re: Quick Authentication June 14, 2009 04:25PM |
Registered: 16 years ago Posts: 12 |
I think I'm missing something really obvious, here -- I didn't see any 1,2,3 steps to implementing this script so I figured it was pretty easy.
My complete process:
I downloaded the most recent version (quick_auth.php, ver 5.2), plopped it in my /lib directory, put the following in my front page:
and I get the "logged out" printout. I've checked my phorum_session_v5 cookie and I am on the same domain with the path set as /. I'm also currently logged in to my phorum. I feel like I'm missing something.
Edited 1 time(s). Last edit at 06/14/2009 04:32PM by strangebeer.
My complete process:
I downloaded the most recent version (quick_auth.php, ver 5.2), plopped it in my /lib directory, put the following in my front page:
require_once("/home/dcshows/www/lib/quick_auth.php"); if($USER["user_id"]){ echo "logged in"; } else { echo "logged out"; }
and I get the "logged out" printout. I've checked my phorum_session_v5 cookie and I am on the same domain with the path set as /. I'm also currently logged in to my phorum. I feel like I'm missing something.
Edited 1 time(s). Last edit at 06/14/2009 04:32PM by strangebeer.
June 14, 2009 04:30PM |
Admin Registered: 20 years ago Posts: 8,532 |
One step that is not in your complete process description, is the actual inclusion of the quick auth script in your front page code. Based on your description, that would be the first available culprit.
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
Maurice Makaay
Phorum Development Team



Re: Quick Authentication June 14, 2009 04:32PM |
Registered: 16 years ago Posts: 12 |
June 14, 2009 05:36PM |
Admin Registered: 20 years ago Posts: 8,532 |
Well, in that case it should work.
Try to do some debugging to see if the quick auth script is loaded and what route it is following.
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
Try to do some debugging to see if the quick auth script is loaded and what route it is following.
Maurice Makaay
Phorum Development Team



Re: Quick Authentication June 14, 2009 06:04PM |
Registered: 16 years ago Posts: 12 |
I've interspersed print statements throughout quick_auth.php. Below is what follows. The bold HEREs indicate where the script went:
<?php HERE print "<p>quick_auth.php loaded<br />"; #DEBUG LINE if(isset($_COOKIE["phorum_session_v5"])){ HERE print "_COOKIE[\"phorum_session_v5\"] set<br />"; #DEBUG LINE if(isset($PHORUM["user"])){ print "_PHORUM[\"user\"] set<br />"; #DEBUG LINE $GLOBALS["USER"] = $PHORUM["user"]; } else { HERE print "_PHORUM[\"user\"] not set<br />"; #DEBUG LINE 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 = "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 HERE print "Require: $require<br />"; include_once($_SERVER["DOCUMENT_ROOT"]."/board/include/db/config.php"); list( $user_id, $sess_id ) = explode( ":", $_COOKIE["phorum_session_v5"], 2 ); $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)){ HERE print "Results found for ".$PHORUM["DBCONFIG"]["table_prefix"]."_users where user_id='".mysql_escape_string($user_id)."<br />"; #DEBUG LINE $USER=mysql_fetch_assoc($res); $sql="select data from ".$PHORUM["DBCONFIG"]["table_prefix"]."_settings where name='PROFILE_FIELDS'"; $res=mysql_query($sql, $conn); if(mysql_num_rows($res)){ HERE print "Data found for ".$PHORUM["DBCONFIG"]["table_prefix"]."_settings where name='PROFILE_FIELDS' <br />"; #DEBUG LINE $fields=unserialize(mysql_result($res, 0, "data")); $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_assoc($res)){ HERE print "Row data: ".$row["data"]."<br />"; $USER[$fields[$row["type"]]["name"]]=$row["data"]; } } } } else { print "No user found<br />"; #DEBUG LINE $USER=array(); }Everything goes great until I get to this point. The following print statement elicits the value "Array" as what is inside $GLOBALS["USER"]. That doesn't seem right to me.
$GLOBALS["USER"]=$USER; HERE print "GLOBALS['USER']: ".$GLOBALS["USER"]."<br />"; } check_session(); } } ?>
June 14, 2009 07:36PM |
Admin Registered: 20 years ago Posts: 8,532 |
That is exactly what I'd expect to be in there: an array (containing no data or a bunch of user data). To see what's in the user data array, use print_r($GLOBALS['USER']) instead. You cannot display an array's contents using a simple print statement.
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
Maurice Makaay
Phorum Development Team



Sorry, only registered users may post in this forum.