vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Calling vb username in another app (https://vborg.vbsupport.ru/showthread.php?t=61953)

pgowder 02-26-2004 07:30 PM

Calling vb username in another app
 
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
PHP Code:

$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

Quote:

Originally Posted by vbmechanic
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

Quote:

Originally Posted by KirbyDE
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
PHP Code:

$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

Quote:

Originally Posted by KirbyDE
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
PHP Code:

$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

PHP 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??


PHP Code:

<?

//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()


All times are GMT. The time now is 02:17 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01052 seconds
  • Memory Usage 1,765KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete