PDA

View Full Version : Calling vb username in another app


pgowder
02-26-2004, 07:30 PM
I know that I can require global.php and then call variables like $bbuserid and $bbusername. I've done that on pages I've built before.

What I need now is to pre-populate the form of another app. It's a recipe sharing script.

Here:

www.powwows.com/gathering/cookbook

I want to have the name and email prepopulated on the add recipe page.

I've trying adding require global.php and putting it in the main vb directory, but that apparently messes up it's internal mysql statements.

Is there another way I can call the information from the cookies? Or some other way??

Thanks

vbmechanic
02-26-2004, 07:42 PM
Try leaving it in it's original directory and changing directories to vB before calling global.

chdir ('../forum');
require_once ('./global.php');

etc. where the first line contains the relative path to the forums.

Andreas
02-26-2004, 07:48 PM
Yes, you can avoid using global.php.

The important cookies are bbuserid and bbpassword.

If you have these cookies you can verify if the combination is valid and retrieve the username from table user.

For vB3

$userid = intval($_COOKIE[bbuserid]);
$password = addslashes($_COOKIE[bbpassword]);
$result = mysql_query("SELECT username, userid FROM user WHERE userid=$userid AND MD5(CONCAT(password, 'LicenseNo')) = '$password'");
$user = mysql_fetch_array($result);
if ($user[userid])
// valid
else
// invalid


Please note that LicenseNo must be replaced with you vB license number.
You must also make sure that you have selected the correct database before executing this query, if your other tables are in another database.

pgowder
02-26-2004, 09:59 PM
Try leaving it in it's original directory and changing directories to vB before calling global.

chdir ('../forum');
require_once ('./global.php');

etc. where the first line contains the relative path to the forums.

Will I need to change it back to the orignal directory after I call global?

pgowder
02-26-2004, 10:00 PM
Yes, you can avoid using global.php.

The important cookies are bbuserid and bbpassword.

If you have these cookies you can verify if the combination is valid and retrieve the username from table user.

For vB3

$userid = intval($_COOKIE[bbuserid]);
$password = addslashes($_COOKIE[bbpassword]);
$result = mysql_query("SELECT username, userid FROM user WHERE userid=$userid AND MD5(CONCAT(password, 'LicenseNo')) = '$password'");
$user = mysql_fetch_array($result);
if ($user[userid])
// valid
else
// invalid


Please note that LicenseNo must be replaced with you vB license number.
You must also make sure that you have selected the correct database before executing this query, if your other tables are in another database.

Will this work in vB 2.x??

vbmechanic
02-26-2004, 10:45 PM
>>Will I need to change it back to the orignal directory after I call global?

Always a good idea, I meant to add that in my original reply.

pgowder
02-26-2004, 11:14 PM
Yes, you can avoid using global.php.

The important cookies are bbuserid and bbpassword.

If you have these cookies you can verify if the combination is valid and retrieve the username from table user.

For vB3

$userid = intval($_COOKIE[bbuserid]);
$password = addslashes($_COOKIE[bbpassword]);
$result = mysql_query("SELECT username, userid FROM user WHERE userid=$userid AND MD5(CONCAT(password, 'LicenseNo')) = '$password'");
$user = mysql_fetch_array($result);
if ($user[userid])
// valid
else
// invalid


Please note that LicenseNo must be replaced with you vB license number.
You must also make sure that you have selected the correct database before executing this query, if your other tables are in another database.

I ended up using this and it worked great!!

Anyway to force the nopermission function with this?

Thanks!

pgowder
02-27-2004, 05:42 PM
Ok that didn't work exactly how I needed. The two apps are in different databases. So I'm using this code

//connect to database
$hostname = "localhost";
$username = "username";
$password = "password";
$dbName = "vBulletin";
$conn = MYSQL_CONNECT($hostname,$username,$password) or die(mysql_error());
@mysql_select_db("$dbName") or die("Unable to select database");

$userid = intval($_COOKIE[bbuserid]);
$password = addslashes($_COOKIE[bbpassword]);
$result = mysql_query("SELECT username, userid FROM user WHERE userid=$userid AND MD5(CONCAT(password, 'licensenumber')) = '$password'");
$user = mysql_fetch_array($result);

Whenc I call $userid I get the right user id of the person logged in. But if I call $username I get the username used to log into MySQL not the vBulletin user???

pgowder
02-27-2004, 06:07 PM
Shouldn't this work?? I get userid, but no username??


<?

//bbusername

//connect to database
$hostname = "localhost";
$dbusername = "username";
$password = "password";
$dbName = "vBulletin";
$conn = MYSQL_CONNECT($hostname,$dbusername,$password) or die(mysql_error());
@mysql_select_db("$dbName") or die("Unable to select database");

$userid = intval($_COOKIE[bbuserid]);
$password = addslashes($_COOKIE[bbpassword]);
$result = mysql_query("SELECT username, userid FROM user WHERE userid=$userid AND MD5(CONCAT(password, 'licensenumber')) = '$password'");
$user = mysql_fetch_array($result);

echo $userid;
echo $username;
echo $user["username"]
?>

Andreas
02-27-2004, 06:12 PM
This should work.
Did you check that both cookies are set?
Did you put in the correct license number (you can verify this on top of each PHP file)?
Is $user[userid] set ($userid doesn't mean anything, as this will always be the value from the cookie if set)?

You should add $conn as a second parameter to mysql_query()

gmarik
02-28-2004, 05:30 PM
Could somebody release this as hack, please?

pgowder
03-05-2004, 05:17 PM
This should work.
Did you check that both cookies are set?
Did you put in the correct license number (you can verify this on top of each PHP file)?
Is $user[userid] set ($userid doesn't mean anything, as this will always be the value from the cookie if set)?

You should add $conn as a second parameter to mysql_query()

Did all that and I still only get my userid, not the person logged in?

pgowder
03-09-2004, 01:39 PM
Can anyone help??

pgowder
03-09-2004, 02:25 PM
This should work.
Did you check that both cookies are set?
Did you put in the correct license number (you can verify this on top of each PHP file)?
Is $user[userid] set ($userid doesn't mean anything, as this will always be the value from the cookie if set)?

You should add $conn as a second parameter to mysql_query()

Can you show me what you mean by adding that in the query statement?

eob
05-26-2004, 02:48 PM
Just found this code, who do I kiss? :D

pgowder
05-26-2004, 02:53 PM
I'm married, but send me a picture...
:squareeyed:

Cold Steel
06-30-2004, 05:48 PM
This was awesome.

Thank you.

Cold Steel
06-30-2004, 08:46 PM
Now, the question is...

I have myforums.com
I also have mysite.com

If I log into myforums.com, then I have no problem logging into mysite.com (cookies, I guess).

Is there anyway of letting me log in to mysite.com without having to log in to myforums.com?

Rochdale
01-06-2006, 09:21 AM
I found this very useful too, thanks very much :)