How to setup php.init file into F3 config.ini file

67 views
Skip to first unread message

Joseph Asamoah

unread,
Mar 22, 2022, 8:54:56 AM3/22/22
to Fat-Free Framework
Hi, i am trying to implement US (userspice) with F3 and US has this .init file that stores DB details, seesion and other site details. I want to know how i can convert this file into F3 config file.

<?php
require_once 'classes/class.autoloader.php';
session_start();

$abs_us_root=$_SERVER['DOCUMENT_ROOT'];

$self_path=explode("/", $_SERVER['PHP_SELF']);
$self_path_length=count($self_path);
$file_found=FALSE;

for($i = 1; $i < $self_path_length; $i++){
        array_splice($self_path, $self_path_length-$i, $i);
        $us_url_root=implode("/",$self_path)."/";

        if (file_exists($abs_us_root.$us_url_root.'z_us_root.php')){
                $file_found=TRUE;
                break;
        }else{
                $file_found=FALSE;
        }
}

require_once $abs_us_root.$us_url_root.'users/helpers/helpers.php';

// Set config
$GLOBALS['config'] = array(
        'mysql'      => array(
'host'         => 'localhost',
'username'     => 'wapknhmx_user410',
'password'     => '[4](6Q[aS9X3pY',
'db'           => 'wapknhmx_user410',
),
'remember'        => array(
  'cookie_name'   => 'hltXeZOavroCJ0SLsL16',
  'cookie_expiry' => 604800  //One week, feel free to make it longer
),
'session' => array(
  'session_name' => 'CA4ptfcSkO6H8VWVJEV7',
  'token_name' => 'token',
)
);

//If you changed your UserSpice or UserCake database prefix
//put it here.
$db_table_prefix = "uc_";  //Old database prefix

//adding more ids to this array allows people to access everything, whether offline or not. Use caution.
$master_account = [1];

$currentPage = currentPage();

//Check to see if user has a remember me cookie
if(Cookie::exists(Config::get('remember/cookie_name')) && !Session::exists(Config::get('session/session_name'))){
        $hash = Cookie::get(Config::get('remember/cookie_name'));
        $hashCheck = DB::getInstance()->query("SELECT * FROM users_session WHERE hash = ? AND uagent = ?",array($hash,Session::uagent_no_version()));

        if ($hashCheck->count()) {
                $user = new User($hashCheck->first()->user_id);
                $user->login();

        }
}

//Check to see that user is logged in on a temporary password
$user = new User();

//Check to see that user is verified
if($user->isLoggedIn()){
        if($user->data()->email_verified == 0 && $currentPage != 'verify.php' && $currentPage != 'logout.php' && $currentPage != 'verify_thankyou.php'){
                Redirect::to($us_url_root.'users/verify.php');
        }
}
$timezone_string = 'America/New_York';
date_default_timezone_set($timezone_string);

require_once $abs_us_root.$us_url_root."users/includes/loader.php";      

ved

unread,
Mar 22, 2022, 11:21:42 AM3/22/22
to Fat-Free Framework
Hi,

I don't think you can convert it completely because that file is filled with php logic and config files are for basic configuration settings only.

You can (probably) place the DB connection details in your F3 config and then call $f3->get('some_variable_from_f3_config') inside this file where appropriate.

Cheers

Joseph Asamoah

unread,
Mar 22, 2022, 11:41:06 AM3/22/22
to Fat-Free Framework
Thanks, ved
Reply all
Reply to author
Forward
0 new messages