1

Topic: relative url as forum_root ?

the first thing i learned on php that relative urls are bad

they never works as expect on diffrent options (include from other directories ,  running as cron , and can security risk if you dont handle included file checks)

here is 2 links hack that will make punbb much better

index.php

if (!defined('FORUM_ROOT'))
    define('FORUM_ROOT', './');

change to

if (!defined('FORUM_ROOT'))
define('FORUM_ROOT',dirname(__FILE__).DIRECTORY_SEPARATOR);

and include/common.php

find :

if (!defined('FORUM_ROOT'))
    exit('The constant FORUM_ROOT must be defined and point to a valid PunBB installation root directory.');

change to :

if (!defined('FORUM_ROOT'))
    define('FORUM_ROOT',dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR);

this way , when i builld integration i dont need to care about forum_root define (and i saw some posts around that ppl got lost tring to figure out forum_root dir)

the point about __FILE__ is thats its allways return the currect working file .

few more points :

punbb allways uses '/' as DIRECTORY SEPARATOR this might couse some problems on some configuration of windows iis

the fix is very simple , use php language const : DIRECTORY_SEPARATOR

or if you want to make it simple , just put define('DS',DIRECTORY_SEPARATOR);
somewhere so we can all use it as

require FORUM_ROOT.'include'.DS.'file.php';

also i think its will be better to set few consts for development ( will help ext developers as well) for example

define('FORUM_INC',FORUM_ROOT.'include'.DS);
define('FORUM_EXT',FORUM_ROOT.'extentions'.DS);

same for languages &&  other stuff that used alot at punbb

its not a really a bug , but its imporvment , for security and for code writing.

i hope i will get punbb developers comments as well.

thanks.

Re: relative url as forum_root ?

I've added the relative url theme to trac
http://punbb.informer.com/trac/ticket/356

hopefully alexp, slavok will comment...

3

Re: relative url as forum_root ?

More on integration info

the function add_user should return $new_uid

this way we keen save the forum userid in our database

1 more thing you request for

function add_user($user_info, &$new_uid)

but when inserting query you dont push the $new_uid.

and if you request for new_uid why to ask only for variable ?

this way we cant do add_user($userinfo,0); or add_user($userinfo,null);

so the workaround is

$uid = null;
add_user($userinfo,$uid);

(and you igone $uid anyway so whats the point ? )

4

Re: relative url as forum_root ?

and 1 more thing

 
        $mail_message = str_replace('<base_url>', $base_url.'/', $mail_message);
        $mail_message = str_replace('<username>', $user_info['username'], $mail_message);
        $mail_message = str_replace('<activation_url>', str_replace('&amp;', '&', forum_link($forum_url['change_password_key'], array($new_uid, substr($user_info['activate_key'], 1, -1)))), $mail_message);
        $mail_message = str_replace('<board_mailer>', sprintf($lang_common['Forum mailer'], $forum_config['o_board_title']), $mail_message);

why to call str_replace each time ? just combine all of it togeder like :

$find = array('<base_url>','<username>','<activation_url>','<board_mailer>');
        $replace = array(
                $base_url.'/',
                $user_info['username'],
                str_replace('&amp;', '&', forum_link($forum_url['change_password_key'], array($new_uid, substr($user_info['activate_key'], 1, -1)))),
                sprintf($lang_common['Forum mailer'], $forum_config['o_board_title'])
        );
        $mail_message = str_replace($find,$replace,$mail_message);

will require less resources from the server to run str_replace once then 5 times.

Re: relative url as forum_root ?

rs324 wrote:

punbb allways uses '/' as DIRECTORY SEPARATOR this might couse some problems on some configuration of windows iis

the fix is very simple , use php language const : DIRECTORY_SEPARATOR

Thanks for the this. We will add it.

they never works as expect on diffrent options (include from other directories ,  running as cron , and can security risk if you dont handle included file checks)

Can you post examples,  please.

rs324 wrote:

More on integration info

the function add_user should return $new_uid

this way we keen save the forum userid in our database

1 more thing you request for

function add_user($user_info, &$new_uid)

Yes, it will easier to use your method.

why to call str_replace each time ? just combine all of it togeder like :

$find = array('<base_url>','<username>','<activation_url>','<board_mailer>');
        $replace = array(
                $base_url.'/',
                $user_info['username'],
                str_replace('&amp;', '&', forum_link($forum_url['change_password_key'], array($new_uid, substr($user_info['activate_key'], 1, -1)))),
                sprintf($lang_common['Forum mailer'], $forum_config['o_board_title'])
        );
        $mail_message = str_replace($find,$replace,$mail_message);

Thanks for this, we will update it.

6

Re: relative url as forum_root ?

Can you post examples,  please.

here is an example to relative path problem


file1.php

<?php print 'i am file1.php' ?>

index.php

<?php
error_reporting(E_ALL);

require './file1.php'

?>

now go to ssh and do

path/to/php -f /var/www/html/index.php

if you have done it , you will see he cant find file1.php

becouse execute dir is not the same as public_html dir
but if index.php will look like this
<?php
error_reporting(E_ALL);
define('FORM_ROOT',dirname(__FILE__).DIRECTORY_SEPARATOR);
require FORM_ROOT.'file1.php'

?>

the file will work without any problems

other methods is :

chdir(dirname(__FILE));

at top of the code ... might couse problems if i include the forum from other direcrtory

or you can use set_include_path but its have the same issue as chdir option.


btw

the function add_user have

global ...... , $lang_register .........

but forum dont have lang_register at all......