Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-03-2006, 04:12 PM
fabrizio fabrizio is offline
 
Join Date: Feb 2004
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How to login an user from an external script?

Hello,
I'd like to be able to login users automatically on vBulletin from my own PHP scripts. Is that possible?

Thank you in advance for any help.

Sincerely,
Fab.

Anyone can help me?

Thank you.

Fabrizio.
Reply With Quote
  #2  
Old 03-04-2006, 04:25 PM
Aesma Deva Aesma Deva is offline
 
Join Date: Feb 2006
Posts: 51
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You could try sending the username and the password to VB's login page, like this:
Code:
<form action="http://www.yoursite.com/path_to_forums/login.php" method="post">
<input type="hidden" name="do" value="login" />
<input type="hidden" name="vb_login_md5password" />
<input type="hidden" name="vb_login_md5password_utf" />
Username: <input type="text" name="vb_login_username" /><br />
Password: <input type="password" name="vb_login_password" /><br />
Remember me: <input type="checkbox" name="cookieuser" /><br />
<input type="submit" value="Log in" />
</form>
Reply With Quote
  #3  
Old 03-04-2006, 05:59 PM
fabrizio fabrizio is offline
 
Join Date: Feb 2004
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you for your reply. Actually I asked to know the actual PHP code for login, but I was able to figure it out myself from the login.php script of vBulletin...

Thank you anyway!

Sincerely,
Fabrizio
Reply With Quote
  #4  
Old 05-25-2006, 03:05 AM
bfc bfc is offline
 
Join Date: May 2006
Posts: 4
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Great now can those of us who do not know how to use php that well know how you did it?
Reply With Quote
  #5  
Old 05-25-2006, 08:26 PM
fabrizio fabrizio is offline
 
Join Date: Feb 2004
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, of course, I must apologize... here i the code I created myself, you can adapt it on your own system:

Code:
$vb_login_username = $username1;
$vb_login_password = $pw;
$tempo = time();

#Define $scriptpath
if ($_ENV['REQUEST_URI'] OR $_SERVER['REQUEST_URI'])
{
	$scriptpath = $_SERVER['REQUEST_URI'] ? $_SERVER['REQUEST_URI'] : $_ENV['REQUEST_URI'];
}
else
{
	if ($_ENV['PATH_INFO'] OR $_SERVER['PATH_INFO'])
	{
		$scriptpath = $_SERVER['PATH_INFO'] ? $_SERVER['PATH_INFO']: $_ENV['PATH_INFO'];
	}
	else if ($_ENV['REDIRECT_URL'] OR $_SERVER['REDIRECT_URL'])
	{
		$scriptpath = $_SERVER['REDIRECT_URL'] ? $_SERVER['REDIRECT_URL']: $_ENV['REDIRECT_URL'];
	}
	else
	{
		$scriptpath = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_ENV['PHP_SELF'];
	}

	if ($_ENV['QUERY_STRING'] OR $_SERVER['QUERY_STRING'])
	{
		$scriptpath .= '?' . ($_SERVER['QUERY_STRING'] ? $_SERVER['QUERY_STRING'] : $_ENV['QUERY_STRING']);
	}
}

$scriptpath = preg_replace('/(s|sessionhash)=[a-z0-9]{32}?&?/', '', $scriptpath);
$find = array('"', '<', '>');
$replace = array('&quot;', '&lt;', '&gt;');
$scriptpath = preg_replace('/javascript/i', 'java script', $scriptpath);
$scriptpath = str_replace($find, $replace, $var);

#Define ALT_IP
if ($_SERVER['HTTP_CLIENT_IP'])
{
	define('ALT_IP', $_SERVER['HTTP_CLIENT_IP']);
}
else if ($_SERVER['HTTP_X_FORWARDED_FOR'] AND preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches))
{
	// make sure we dont pick up an internal IP defined by RFC1918
	foreach ($matches[0] AS $ip)
	{
		if (!preg_match("#^(10|172\.16|192\.168)\.#", $ip))
		{
			define('ALT_IP', $ip);
			break;
		}
	}
}
else if ($_SERVER['HTTP_FROM'])
{
	define('ALT_IP', $_SERVER['HTTP_FROM']);
}
else
{
	define('ALT_IP', $_SERVER['REMOTE_ADDR']);
}

#Define SESSION_IDHASH e altri...
define('SESSION_IDHASH', md5($_SERVER['HTTP_USER_AGENT'] . ALT_IP ));
define('IPADDRESS', $_SERVER['REMOTE_ADDR']);		
define('SESSION_HOST', substr(IPADDRESS, 0, 15));

function vbrandFABRI($min, $max, $seed = -1)
{

	if (!defined('RAND_SEEDED'))
	{
		if ($seed == -1)
		{
			$seed = (double) microtime() * 1000000;
		}

		mt_srand($seed);
		define('RAND_SEEDED', true);
	}

	return mt_rand($min, $max);
}

function iifFABRI($expression, $returntrue, $returnfalse = '')
{
	return ($expression ? $returntrue : $returnfalse);
}



// can the user login?

$username = &$vb_login_username;
$password = &$vb_login_password;
$md5password = &$vb_login_md5password;
$md5password_utf = &$vb_login_md5password_utf;

$sessionFABRI = array(
'sessionhash' => md5($tempo.$scriptpath.SESSION_IDHASH.SESSION_HOST.vbrandFABRI(1, 1000000)),
'userid' => intval($userid),
'host' => SESSION_HOST,
'idhash' => SESSION_IDHASH,
'lastactivity' => $tempo,
'location' => $scriptpath,
'styleid' => 0,
'useragent' => $_SERVER['HTTP_USER_AGENT'],
'loggedin' => 0
);

$sessionFABRI['dbsessionhash'] = $sessionFABRI['sessionhash'];

#Main procedure...


$queryZZ1 = "DELETE FROM vb3_session WHERE sessionhash = '" . addslashes($sessionFABRI['dbsessionhash']) . "'";
$resultZZ1 = @mysql_query($queryZZ1);

$sessionFABRI['sessionhash'] = md5($tempo.$scriptpath.SESSION_IDHASH.SESSION_HOST.vbrandFABRI(1, 1000000));
$sessionFABRI['dbsessionhash'] = $sessionFABRI['sessionhash'];







$queryZZ2 = "INSERT INTO vb3_session
		(sessionhash, userid, host, idhash, lastactivity, styleid, loggedin, bypass, useragent)
	VALUES
		('" . addslashes($sessionFABRI['sessionhash']) . "', " . intval($userid) . ", '" . addslashes(SESSION_HOST) . "', '" . addslashes(SESSION_IDHASH) . "', " . $tempo . ", $sessionFABRI[styleid], 1, " . iifFABRI ($logintype === 'cplogin', 1, 0) . ", '" . addslashes($_SERVER['HTTP_USER_AGENT']) . "')";
$resultZZ2 = @mysql_query($queryZZ2);

setcookie('bbsessionhash', $sessionFABRI['sessionhash'], 0,'/');

#Set cookies

setcookie('bbuserid', $userid, time()+60*60*24*365,'/');
setcookie('bbpassword', md5($password1 . 'L489612f'), time()+60*60*24*365,'/');
Reply With Quote
  #6  
Old 04-27-2007, 11:11 AM
wcm wcm is offline
 
Join Date: Sep 2006
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Digging up a zombie here...

This code worked perfectly with 3.6.1. I recently upgraded to 3.6.5 and now it does not. Has anything in the way login/cookie/session works been changed with the recent patches? If so, how?
Reply With Quote
  #7  
Old 04-28-2007, 02:37 AM
hotmasala4u hotmasala4u is offline
 
Join Date: Nov 2006
Posts: 64
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

yea i also wanna know how to make the same usernames/passwords as vb to work on other pages. please help me
Reply With Quote
  #8  
Old 05-09-2007, 05:24 PM
ricc ricc is offline
 
Join Date: Apr 2007
Location: Preston
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have the same problem and asked on other websites, but no-one seems to know how to login a user onto another non-vb page using their details in the vb forum
Reply With Quote
  #9  
Old 05-11-2007, 03:28 AM
Wizardjv Wizardjv is offline
 
Join Date: Feb 2006
Posts: 111
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well an easy way to do this would be...

HTML Code:
<?php

require('./global.php');   ?>
Though if you move the page outside of the forum you would have to edit the location of global.php

Then add a if statement

HTML Code:
<? 
if (!is_member_of($vbulletin->userinfo, 6)  AND !is_member_of($vbulletin->userinfo, 13)  AND !is_member_of($vbulletin->userinfo, 5))
{
    print_no_permission();
}  
?>

This way only those user groups you define that can view the custom page can see it. Also if they are not signed in they will have to login via the vbulletin login system to see the page


Though this is a lil different than adding a login form. But should work.If want everyone to see it and login. Just add an
HTML Code:
AND !is_member_of($vbulletin->userinfo, 5)
for everyone.

By the way you would add this at the top of the page
Reply With Quote
  #10  
Old 05-12-2007, 07:10 PM
ricc ricc is offline
 
Join Date: Apr 2007
Location: Preston
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by hotmasala4u View Post
yea i also wanna know how to make the same usernames/passwords as vb to work on other pages. please help me
I had help on a similar problem in this thread, hope it helps

https://vborg.vbsupport.ru/showthread.php?t=146089
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:52 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07560 seconds
  • Memory Usage 2,264KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (3)bbcode_html
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete