External Login for phpBB

Ask about a PHP problem here.
Post Reply
SicX
Posts: 26
Joined: Fri Jun 15, 2012 1:03 pm

External Login for phpBB

Post by SicX »

Hey :)
It's me again! ;-) I'm working on an external login /(atm. mainly) register formular for phpBB. A functional register script looks like this:
$user->setup();

    /* globale variablen setzen */
    global $phpbb_root_path;
    global $phpEx;
    global $db;
    global $config;
    global $user;
    global $auth;
    global $cache;
    global $template;


    /* Datei inkludieren die die benoetigten Funktionen beinhaltet */
    require($phpbb_root_path .'includes/functions_user.php');

    
    
    /* Daten in array schreiben */
    $user_row = array(
    'username' => 'testingo',
    'user_password' => md5('testingo'), 
    'user_email' => 'testing@example.com',
    'group_id' => '2',
    'user_timezone' => '1.00',
    'user_dst' => '0',
    'user_lang' => 'de',
    'user_type' => '0',
    'user_actkey' => '',
    'user_dateformat' => 'd M Y H:i',
    'user_style' => '1',
    'user_regdate' => time(),
    );

    /* User anlegen */
    if($phpbb_user_id = user_add($user_row)){
    echo "okay";
    }
    else
    {
    echo "nicht O.K!";
    }
   ?>
Now I want to add another file with forms to fill this out. My problem is:
How do I get the vars. from the form to this file? Would it work with, for example:
$user_row = array(
    'username' => '$_POST[$username]',
(with or without the > ' < ?)

or

say:
$_POST[$username] = $username;

$user_row = array(
    'username' => '$username',
The idea behind that is, that users of my homepage just have to register one time :)
Hope you can help me!

SicX (:
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: External Login for phpBB

Post by Temor »

it should work without the semi-quotes ( ' ).
SicX
Posts: 26
Joined: Fri Jun 15, 2012 1:03 pm

Re: External Login for phpBB

Post by SicX »

Hmm, doesn't seem to work!
Always says: "Nicht O.K!" (= failture ;-))
Any idea what I've made wrong?
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: External Login for phpBB

Post by Temor »

Well, it's most likely because of this part right here.
<?php
 if($phpbb_user_id = user_add($user_row)){
    echo "okay";
    }
    else
    {
    echo "nicht O.K!";
    }
What is the value of $phpbb_user_id and what does user_add do exactly?

This will always return "nicht O.K" if the user_add function does not return the same value as $phpbb_user_id.
SicX
Posts: 26
Joined: Fri Jun 15, 2012 1:03 pm

Re: External Login for phpBB

Post by SicX »

This script was published on the original phpBB forum from a user. The Script works, I've tested it by opening it directy (www.domain.de/test.php). And it adds the User which I want to. The only prob. is, to fill this file out with the forms!
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: External Login for phpBB

Post by Temor »

Oh, I just noticed a typo.
$_POST[$username] = $username;
You're not supposed to define a variable inside the $_POST variable, and also, you're assigning an empty variable ( $username ) to the $_POST variable. That should be the other way around.

It's supposed to be
$username = $_POST['username'];
SicX
Posts: 26
Joined: Fri Jun 15, 2012 1:03 pm

Re: External Login for phpBB

Post by SicX »

Hey,
sorry for this late reply, got a lot of work to do :-/

Well if changed it as you said but it doesn't changed anything!
If I'm using the ' ' the username, password and email will always be the variables (=> username: $username | password: $password | email: $email), but if i'm not using the ' ' the script won't work! :(

Is there any stupid mistake I don't see?
<?php     
    // Funktionen von PHPBB3 holen
define('IN_PHPBB', true);
$phpbb_root_path = './'; // PHPBB3 root ordner
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Sessionsverwaltung starten
$user->session_begin();
$auth->acl($user->data);
$user->setup();

    /* globale variablen setzen */
    global $phpbb_root_path;
    global $phpEx;
    global $db;
    global $config;
    global $user;
    global $auth;
    global $cache;
    global $template;


    /* Datei inkludieren die die benoetigten Funktionen beinhaltet */
    require($phpbb_root_path .'includes/functions_user.php');

    $username = $_POST['username'];
    $passwort = $_POST['password'];
    $email = $_POST['email'];
    
    /* Daten in array schreiben */
    $user_row = array(
    'username' => $username,
    'user_password' => md5($password), 
    'user_email' => $email,
    'group_id' => '2',
    'user_timezone' => '1.00',
    'user_dst' => '0',
    'user_lang' => 'de',
    'user_type' => '0',
    'user_actkey' => '',
    'user_dateformat' => 'd M Y H:i',
    'user_style' => '1',
    'user_regdate' => time(),
    );

    /* User anlegen */
    if($phpbb_user_id = user_add($user_row)){
    echo "okay";
    }
    else
    {
    echo "nicht O.K!";
    }
?>
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: External Login for phpBB

Post by Temor »

try removing the last trailing comma.
after this line:
 'user_regdate' => time() 
A comma is an indication that there will be another row, but there isn't one.
SicX
Posts: 26
Joined: Fri Jun 15, 2012 1:03 pm

Re: External Login for phpBB

Post by SicX »

Hey,
removing the trailing comma has no effekt on the script, it just prints: "nicht O.K!"

I don't get it ... normaly it should work!
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: External Login for phpBB

Post by Temor »

You misspelled password.
 $passwort = $_POST['password'];
not sure if that would cause it to fail though. If that doesn't fix it, try printing the array.
print_r($user_row);
SicX
Posts: 26
Joined: Fri Jun 15, 2012 1:03 pm

Re: External Login for phpBB

Post by SicX »

Ups :P
Well doesn't seem to work!
Array:
Array ( [username] => [user_password] => d41d8cd98f00b204e9800998ecf8427e [user_email] => [group_id] => 2 [user_timezone] => 1.00 [user_dst] => 0 [user_lang] => de [user_type] => 0 [user_actkey] => [user_dateformat] => d M Y H:i [user_style] => 1 [user_regdate] => 1341086164 )
Why can't I set username, password and email in this array :@
Are there any codes which don't allow to edit an array or something like this?
Maybe I should check the includes for something like this!
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: External Login for phpBB

Post by Temor »

Password is being set, is it not?
This:
d41d8cd98f00b204e9800998ecf8427e
looks like an md5 hash to me :)

The only logical explanation now is that $_POST['username'] and $_POST['email'] never get a value. Make sure there's no typo in the field names in your HTML form.
SicX
Posts: 26
Joined: Fri Jun 15, 2012 1:03 pm

Re: External Login for phpBB

Post by SicX »

aah! I'm sooo stupid!
You're right, there was an typo!
Thats embarrassing! :oops:

Oh come on, why do I allways such little mistakes :(
I'm sorry but I didn't checked it one time cause I thought everything is correct! :?
Thank you for your help :D

SicX :)
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: External Login for phpBB

Post by Temor »

You're welcome. You're now a little bit more experienced! Next time, you'll check your forms.
Yay to making mistakes! :)
Post Reply