Insert a user into phpBB from PHP

Discussion forum for MOD Writers regarding MOD Development.
amochohan
Registered User
Posts: 92
Joined: Tue Dec 11, 2007 2:59 pm

Re: Insert a user into phpBB from PHP

Post by amochohan »

adamsargant wrote:Cool, glad it is of use...
Your code worked perfectly for me too, thanks! :)
md.carter
Registered User
Posts: 3
Joined: Thu Dec 13, 2007 10:52 am

Re: Insert a user into phpBB from PHP

Post by md.carter »

adamsargant wrote:Chuffin' typical... I make my forehead bleed working on this, post a request, and the answer comes to me minutes later

if it's useful to anyone

Code: Select all

define('IN_PHPBB', true);
$phpbb_root_path = 'pathtoroot/';

$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.php');
include($phpbb_root_path . 'includes/functions_user.php');
include($phpbb_root_path . 'includes/ucp/ucp_register.php');

$password='pword';
$username='uname';
$username_clean=strtolower($username);
$user_email='email@email.net';

    $sql_ary = array(
        'username'          => $username,
        'username_clean'    => $username_clean,
        'user_password'     => phpbb_hash($password),
        'user_pass_convert' => 0,
        'user_email'        => $user_email,
        'user_email_hash'   => crc32(strtolower($user_email)) . strlen($user_email),
        'group_id'          => 2,
        'user_type'         => 0,
    );
user_add($sql_ary);
I'm usin this on my test page but i have this error :
Fatal error: Call to a member function sql_query() on a non-object in /home/..blablabla../cache.php on line 51
What should I do ?

EDIT : I'v put global $db, but there is more error ! Things with utf_tools.php.
Like : Fatal error: Class 'utf_normalizer' not found in /home.. ../includes/utf/utf_tools.php on line 1663
and a lot of notices...
amochohan
Registered User
Posts: 92
Joined: Tue Dec 11, 2007 2:59 pm

Re: Insert a user into phpBB from PHP

Post by amochohan »

I used the code I posted exacltly like that to test on my environment and it worked perfectly. Double check that you've got the path to your forum set up properly etc...post your exact code here and i'll see if i can spot anything.
md.carter
Registered User
Posts: 3
Joined: Thu Dec 13, 2007 10:52 am

Re: Insert a user into phpBB from PHP

Post by md.carter »

Okay, there is my test code :

Code: Select all

		define('IN_PHPBB', true);
		$phpbb_root_path = '/home/Jeu/public_html/Adelian2/prod/forum2/';
	   	global $db;			
		$phpEx = substr(strrchr(__FILE__, '.'), 1);
		include($phpbb_root_path.'common.php');
		include($phpbb_root_path.'includes/functions_user.php');
		include($phpbb_root_path.'includes/ucp/ucp_register.php');
		
		$password='test';
		$username='pass';
		$username_clean=strtolower($username);
		$user_email='email@email.net';
		
		    $sql_ary = array(
		        'username'          => $username,
		        'username_clean'    => $username_clean,
		        'user_password'     => phpbb_hash($password),
		        'user_pass_convert' => 0,
		        'user_email'        => $user_email,
		        'user_email_hash'   => crc32(strtolower($user_email)) . strlen($user_email),
		        'group_id'          => 2,
		        'user_type'         => 0,
		    );
		user_add($sql_ary);
This file is not situated in the same folder that the forum.
Its just a test file but in the future i want to use this to register people who register to my website.
amochohan
Registered User
Posts: 92
Joined: Tue Dec 11, 2007 2:59 pm

Re: Insert a user into phpBB from PHP

Post by amochohan »

[quote="md.carter"]Okay, there is my test code :

Code: Select all

		
		$phpbb_root_path = '/home/Jeu/public_html/Adelian2/prod/forum2/';
	   	

Where is this example php file held? As far as I know $phpbb_root_path is relative to the script being executed. So copy the file into the folder 'prod' and then change the line to:

Code: Select all

$phpbb_root_path = 'forum2/';
Then lets see what happens..
md.carter
Registered User
Posts: 3
Joined: Thu Dec 13, 2007 10:52 am

Re: Insert a user into phpBB from PHP

Post by md.carter »

Yup I tested that juste after post, now i've got alternatively this error :

Code: Select all

SQL ERROR [ mysqli ]
Duplicate entry 'rand_seed_last_update' for key 1 [1062]
and the first error i've got

Code: Select all

[phpBB Debug] PHP Notice: in file /home/Jeu/public_html/Adelian2/prod/forum2/includes/utf/utf_tools.php on line 1824: include(includes/utf/data/confusables.) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Notice: in file /home/Jeu/public_html/Adelian2/prod/forum2/includes/utf/utf_tools.php on line 1824: include() [function.include]: Failed opening 'includes/utf/data/confusables.' for inclusion (include_path='.:/usr/share/php:/usr/share/pear')
[phpBB Debug] PHP Notice: in file /home/Jeu/public_html/Adelian2/prod/forum2/includes/utf/utf_tools.php on line 1042: include(includes/utf/data/case_fold_c.) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Notice: in file /home/Jeu/public_html/Adelian2/prod/forum2/includes/utf/utf_tools.php on line 1042: include() [function.include]: Failed opening 'includes/utf/data/case_fold_c.' for inclusion (include_path='.:/usr/share/php:/usr/share/pear')
[phpBB Debug] PHP Notice: in file /home/Jeu/public_html/Adelian2/prod/forum2/includes/utf/utf_tools.php on line 1048: include(includes/utf/data/case_fold_f.) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Notice: in file /home/Jeu/public_html/Adelian2/prod/forum2/includes/utf/utf_tools.php on line 1048: include() [function.include]: Failed opening 'includes/utf/data/case_fold_f.' for inclusion (include_path='.:/usr/share/php:/usr/share/pear')
[phpBB Debug] PHP Notice: in file /home/Jeu/public_html/Adelian2/prod/forum2/includes/utf/utf_tools.php on line 1058: strtr() [function.strtr]: The second argument is not an array.
[phpBB Debug] PHP Notice: in file /home/Jeu/public_html/Adelian2/prod/forum2/includes/utf/utf_tools.php on line 1063: strtr() [function.strtr]: The second argument is not an array.
[phpBB Debug] PHP Notice: in file /home/Jeu/public_html/Adelian2/prod/forum2/includes/utf/utf_tools.php on line 1659: include(includes/utf/utf_normalizer.) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Notice: in file /home/Jeu/public_html/Adelian2/prod/forum2/includes/utf/utf_tools.php on line 1659: include() [function.include]: Failed opening 'includes/utf/utf_normalizer.' for inclusion (include_path='.:/usr/share/php:/usr/share/pear')

Fatal error: Class 'utf_normalizer' not found in /home/Jeu/public_html/Adelian2/prod/forum2/includes/utf/utf_tools.php on line 1663
Cercetasu
Registered User
Posts: 4
Joined: Sat Dec 01, 2007 11:30 am

Re: Insert a user into phpBB from PHP

Post by Cercetasu »

how do i set the custom profile array for user_add??
and how do i display the custom profile fields on my registration page?
letronje
Registered User
Posts: 2
Joined: Fri May 02, 2008 11:48 am

Re: Insert a user into phpBB from PHP

Post by letronje »

Hi adamsargant,

The "remote log-in" script that you have, what does it do? given username and password, can you login a user through code using the script ( phpbb ver is 3.0.1) ? I badly need such a script. if yes, could you please share it ?
adamsargant
Registered User
Posts: 9
Joined: Tue Nov 21, 2006 11:33 pm

Re: Insert a user into phpBB from PHP

Post by adamsargant »

letronje wrote:Hi adamsargant,

The "remote log-in" script that you have, what does it do? given username and password, can you login a user through code using the script ( phpbb ver is 3.0.1) ? I badly need such a script. if yes, could you please share it ?
That is exactly what it does, so that you can have a forum on your site, but a login elsewhere (it was built for a membership area)

The script is the one I posted above and it works for me, though I've not done any work on that project for months so I've lost my familiarity with the code I had to hack to get it to work

I'm probably going to have to revisit it in a month or so so I'll let you know if it has any problems
adamsargant
Registered User
Posts: 9
Joined: Tue Nov 21, 2006 11:33 pm

Re: Insert a user into phpBB from PHP

Post by adamsargant »

letronje wrote:Hi adamsargant,

The "remote log-in" script that you have, what does it do? given username and password, can you login a user through code using the script ( phpbb ver is 3.0.1) ? I badly need such a script. if yes, could you please share it ?
OK, was muddled... the script in this thread is for subscribing... the remote log in script goes

Code: Select all

                   define('IN_PHPBB', true);
                   $phpbb_root_path = 'relativepathtoroot/';
                   $phpEx = substr(strrchr(__FILE__, '.'), 1);
                   include($phpbb_root_path . 'config.php');
                   include($phpbb_root_path . 'common.php');
                   include($phpbb_root_path . 'includes/auth/auth_db.php');
                   $user->session_begin();
                   $auth->acl($user->data);
                   $user->setup('ucp');
                   $auth->login(username, password);
I use this on my generic log in page for my members area, and it means that people can now go to my forum and find themselves logged in.
mhuggins
Registered User
Posts: 3
Joined: Thu Sep 14, 2006 10:25 pm
Location: Wilmington, DE
Contact:

Re: Insert a user into phpBB from PHP

Post by mhuggins »

Thanks for everyone's input in this thread. I'm looking through the auth.php file, and I see the login functionality. However, I don't see any way to make the user log out. Anyone have any code they'd mind sharing, or a finger they could point in the right direction? Thanks! :)
adamsargant
Registered User
Posts: 9
Joined: Tue Nov 21, 2006 11:33 pm

Re: Insert a user into phpBB from PHP

Post by adamsargant »

kill the session ?
User avatar
joeroberts
Registered User
Posts: 272
Joined: Fri Jun 22, 2007 7:19 pm
Contact:

Re: Insert a user into phpBB from PHP

Post by joeroberts »

Code: Select all

function forumlogout($id){
global $db, $forumpx, $user;
            $cookie_expire = time() +  86400 ;
		 $db->sql_query("DELETE FROM ".$forumpx."_sessions WHERE session_user_id ='".$id."'");
		 $db->sql_query("DELETE FROM ".$forumpx."_sessions_keys WHERE user_id ='".$id."'");

 			set_cookie('u', '', $cookie_expire);
			set_cookie('k', '', $cookie_expire);
			set_cookie('sid', '', $cookie_expire);

}
User avatar
3Di
Former Team Member
Posts: 15854
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Insert a user into phpBB from PHP

Post by 3Di »

mhuggins wrote:Thanks for everyone's input in this thread. I'm looking through the auth.php file, and I see the login functionality. However, I don't see any way to make the user log out. Anyone have any code they'd mind sharing, or a finger they could point in the right direction? Thanks! :)
Try this and let's see.

http://www.phpbb.com/community/viewtopi ... 5#p5542545

Regards
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
:studio_microphone: Looking for a specific feature or alternative option?
BDMcCarthy
Registered User
Posts: 1
Joined: Fri Nov 14, 2008 12:24 am

Re: Insert a user into phpBB from an existing dating app

Post by BDMcCarthy »

I'm sorry to reopen this thread - I realize that it pretty much dried up several months ago except that I'm in quite a quandary

I'm trying to integrate phpBB into an existing dating pro application and I'm at my wits end...I've gone through this entire thread and if I'm not mistaken there is another thread about this topic and it's not that I'm having difficulty with phpBB - it's the dating pro application (finding their user and session management)

I have gotten as far as to find the config file for dating pro so I can at least see how it connects to the db :lol:

and if that isn't enough - I also need to import the forum data from the dating pro app's forum

if anyone is able to help me with this I would so greatly appreciate it! and if I need to create a new topic - by all means let me know :)
Locked

Return to “[3.0.x] MOD Writers Discussion”