1 (edited by riki1512 2006-01-11 13:50)

Topic: single site login trouble

Hi,

the site where my forum occurs can only by accessed by members. I don't want them then to register again in punbb. After i didn't find something like a single-site-login interface or how to for that i tried it quick an dirty by simply calling the punbb-registration-routine when a member registers to my site (whith removing the redirect headers):

# manipulate GET and POST to simulate punbb registration

$_GET['action']         = 'register';
$_POST['form_sent']     = 1;
$_POST['req_username']  = $testerData['username'];
$_POST['req_password1'] = $testerData['password1'];
$_POST['req_password2'] = $testerData['password1'];
$_POST['req_email1']    = $testerData['email'];
$_POST['register']      = 'Register'; # button

chdir ('./punbb');   
require_once ('register.php');
chdir ('../');
   
# *** END of punbb registration ***

Fatal error: Call to a member function on a non-object in /srv/www/htdocs/betatest/punbb/include/functions.php on line 110
Line 110: $result = $db->query('SE.... do'nt have the variable $db in my own code anywhere
version 1.2.10

Idea for the reason or a better way to solve my issue as fast as possible ?

And further, why is the function set_default_user (for guests) called ?

Re: single site login trouble

riki: Why not simply do another insert statement to add the user to the PunBB database?
And as for why set_default_user is called, it's to allow forum permissions and such to be set for guest users

Re: single site login trouble

Smartys wrote:

riki: Why not simply do another insert statement to add the user to the PunBB database?

Because i don't know what is happening before and after (cookies-setting etc.) and I don't want to follow all that code.

Smartys wrote:

And as for why set_default_user is called, it's to allow forum permissions and such to be set for guest users

For 'guest users' after I registered succesfully ?

Re: single site login trouble

Because i don't know what is happening before and after (cookies-setting etc.) and I don't want to follow all that code.

Then perhaps you shouldn't be trying to integrate the code? wink
After all, linking registration and linking login are two different things (your idea links registration)

Re: single site login trouble

He he.

Ok, i wanted to link both, i'll try if it works with linking the login, then i could register manually.

I'm just wondering that isn't a problem that occurs whery often. Maybe someone - i don't have the time :-) - should add 3 functions to functions.php: extern_register(...), extern_login(...) and extern_logout(...).

Re: single site login trouble

Err, why not simply look at the code and replicate what it does? All a function would do is help people who want to be lazy with the integration: integrating what's there is really trivial (assuming the only registration you care about is your own and the other is just so they're logged in within the forums)

Re: single site login trouble

Smartys wrote:

All a function would do is help people who want to be lazy...

That's the sence of functions, api's, oop, frameworks, programming languages, computers and nearly everything in the IT.

Yes, integration should be trivial, an because punbb doesn't use its own sessions, for me it seemed to be very suitable for integrating it into my session-based site. So, if it's that easy, why a simple require doesn't work ?

Smartys wrote:

Err, why not simply look at the code and replicate what it does?

I don't have the time. Easy means for me integratable in 1-2 hours. Nevertheless, thankyou for helping me.

Re: single site login trouble

Yes, integration should be trivial, an because punbb doesn't use its own sessions, for me it seemed to be very suitable for integrating it into my session-based site. So, if it's that easy, why a simple require doesn't work

Because you're attempting to require a page that was expecting a user to be accessing it?
Seriously, you say you don't want it to take more than 2 hours: if you even bothered to read register.php and login.php you'd see that it's trivial to add the queries for PunBB to it

Re: single site login trouble

Because you're attempting to require a page that was expecting a user to be accessing it?

Accessing it directly or including it on the accessed site is not a big difference.

I read register.php an login.php, they include common.php and call functions from functions.php, i overflew all that stuff because i don't have the time to really analyize the code (would write a simple forum in that time), and i saw it's NOT that easy, because it's not structured by a known criteria (like model-view-controller or similar), so i tried to do it quick and dirty. Where's the problem admitting that punbb is not the universal super-forum for every concern (espacially not for my 'quick and dirty' need) ?

Back to the problem:

Including login.php, I get an error 'function call on non-object' on line 110 on functions.php
line 110: $db->query in set_default_user
set_default_user is called in function check_cookie some lines above
check_cookie is called in common.php which again is included in login.php respectively in register.php

with 'global $db' in set_default_user the out-of-function reference of $db should be used, $db is definately called in common.php, before the call of set_default_user, and a print_r of it gives me

dblayer Object
(
    [prefix] => 
    [link_id] => Resource id #33
    [query_result] => 
    [saved_queries] => Array
        (
        )

    [num_queries] => 0
)

A line later the method startTransaction is called in from that object, without error. But, making print_r in the functions where $db is defined global, i don't get the object !? I never use global, maybe i don't understand it - or is it possible to deactivate it in php.ini without getting warnings from the interpreter ?

10 (edited by riki1512 2006-01-12 12:41)

Re: single site login trouble

Tried to refer $db via function parameters in check_cookie and then in set_default_user, the error now is
'There is no valid language pack '' installed. Please reinstall a language of that name.'

Seems 'global' has no effect in my code !?

Checked that, making print_r($db) one line before the call of check_cookie, the correct object is printed, making print_r($GLOBALS) in line two of check_cookie (after global $db, ...), i get

...
    [db] => 
    [pun_config] => 
    [cookie_name] => 
    [cookie_seed] => 
...

The variables are registered, but empty !?

Re: single site login trouble

Accessing it directly or including it on the accessed site is not a big difference

It is when it's supposed to redirect the user to a new page as opposed to giving a "normal" error wink

I read register.php an login.php, they include common.php and call functions from functions.php, i overflew all that stuff because i don't have the time to really analyize the code (would write a simple forum in that time), and i saw it's NOT that easy, because it's not structured by a known criteria (like model-view-controller or similar), so i tried to do it quick and dirty. Where's the problem admitting that punbb is not the universal super-forum for every concern (espacially not for my 'quick and dirty' need) ?

Because after I post this, I'm going to download a copy of PunBB and look at what would need to be added to a login/register page to make it work
I promise you, it will take < 1 hour wink

Re: single site login trouble

OK then smile
register.php
Assuming you already have all the proper checks in your PHP so that everything is in the right format from your form (and you're not relying on PunBB's email reports and you're not using PunBB's email verification), simply add the SQL query as a normal query and set the cookie: 3 lines of code (4 with the comment). You can add more/less depending on what you need from the register.php page

login.php
Look at the code: select the user data, check the password, insert the user into the online table, add a cookie (unless of course you're using the same login criteria, in which case just add the cookie)

Like I said, calling a page that expects a user through a PHP script is a sure way to cause an issue.

I can't do real code unless I see your code wink

Re: single site login trouble

Ok, i'll try that (will take...20 minutes ?), i'm sure there will be problems.

14 (edited by riki1512 2006-01-12 14:44)

Re: single site login trouble

login.php works, but again the same shit ! Keyword global has not really effect, the referenced variables in $GLOBALS are empty ! I had to edit function pun_setcookie in functions.php with "include ('punbb/config.php');" to include the config cookie variables, but i required punbb/config.php just before !?

Why doesn't it cause a problem because of redefining constant PUN !?

Re: single site login trouble

Without seeing the code, I can't really help you
Well, except to tell you that you should change usage of the DB abstraction class to mysql_query (assuming you're using MySQL) since that seems to be a problem with you for whatever reason (did you define $db somewhere in your code?)

16 (edited by riki1512 2006-01-12 16:54)

Re: single site login trouble

Smartys wrote:

Without seeing the code, I can't really help you

Hmm, it's not much code:

# punbb login

require ('conf/conf.php');
require ('punbb/config.php');
require ('punbb/include/functions.php');

mysql_connect ($DB_HOST, $DB_USER, $DB_PASSWORD);
mysql_select_db ('PUNBB');
$result_pun = mysql_query("select id from users where username = '" . trim ($_POST['testerlogin']) . "'");
$row_pun    = mysql_fetch_array ($result_pun);    
pun_setcookie ($row_pun['id'], pun_hash(trim($_POST['password'])), time() + 86400);

# end of punbb login

Nothing complicated, i don't thing that will be helpful for you...

Smartys wrote:

Well, except to tell you that you should change usage of the DB abstraction class to mysql_query (assuming you're using MySQL) since that seems to be a problem with you for whatever reason (did you define $db somewhere in your code?)

I have my own DAO-classes (by Dao-Pattern), but like you see i did it classical for the begin. I am not using $db anywhere (wrote that already somehwere above), really strange.

Nevertheless, you were right. I didn't see that the serialized data in the pun-cookie are all variables from config.php, so i thought i would have to search them all over the script. At the end it's just determining users id for setting the cookie. hmm

17

Re: single site login trouble

riki1512 wrote:

Seems 'global' has no effect in my code !?

I am having the same problem! I am trying to integrate with WordPress, and not is seems that the objects being made global in functions.php are not actually global.

18

Re: single site login trouble

i'm having a similar issue:

http://punbb.org/forums/viewtopic.php?pid=77454#p77454

19

Re: single site login trouble

look at how it does when u login and the login box disappears.
that might be the key..

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!