You Are Here: Home » How-To » Programming

Autoload PHPFox – Access PHPFox From External PHP Scripts [How-To]

By Debjit on February 26th, 2015 
Advertisement

PHPFox is a custom social networking script which you can use to host your own Social Network websites from small scale to large scale ones.

PHPFox Logo

PHPFox Logo

Although the script has ample settings and configurations that can help you to properly set-up or customise the script but at times there are certain things which you might need to do from outside of the PHPFox environment, for eg:

1. Access PHPFox user sessions from an external PHP Script

2. Execute Database queries from inside the PHPFox environment using an external PHP script.

and many others. So lets see how we can do this.

First of all create a php script say load-phpfox.php and place it in the same folder which is the root of your PHPFox installation. In that file add the following contents and save the file:

<?php

/** Required - prevents NO DICE issues*/
define('PHPFOX', true); 
/**  Directory Seperator  */
define('PHPFOX_DS', DIRECTORY_SEPARATOR);

/**  phpFox Root Directory   */
define('PHPFOX_DIR', dirname(__FILE__) . PHPFOX_DS);

//If your external PHP script is in some other directory, say inside
//a sub-directory of the PHPFox root folder then change accordingly,
//ideally it would be like this:
//define('PHPFOX_DIR', '../');

define('PHPFOX_START_TIME', array_sum(explode(' ', microtime())));

// Require phpFox Init
require(PHPFOX_DIR . 'include' . PHPFOX_DS . 'init.inc.php');

//Include your custom code from here
echo "Logged in PHPFOX UID = " . Phpfox::getUserId();
echo "<br />PHPFOX SESSION<br >";
print_r(Phpfox::getService('user.auth')->getUserSession());

//Make a database query in PHPFox using the API
$aRows = Phpfox::getLib('database')->select('*')
->from('phpfox_user')
->where('user_name IN ('john','ethel','dave')
->execute('getRows');

This script can now communicate with the PHPFox system in a legit way and can also access any of its APIs.

***

The next part of the article is specifically for Question2Answer & PHPFox single sign-on integration and if you are here for that, then you have to do the following:

1. Create a file called phpfox-autoload.php and place it in the qa-external folder.

2. Now place the following code snippet inside the above file and save the file:

<?php

/** You can comment this line if you do not get the NO DICE error */
define('PHPFOX', true);
/**  Directory Seperator  */
define('PHPFOX_DS', DIRECTORY_SEPARATOR);

/**  phpFox Root Directory   */
define('PHPFOX_DIR', '../');

define('PHPFOX_START_TIME', array_sum(explode(' ', microtime())));

// Require phpFox Init
require(PHPFOX_DIR . 'include' . PHPFOX_DS . 'init.inc.php');

3. Now you can continue the integration by reading this article - digitizor.com/2014/02/12/phpfox-q2a-sso-compulsory-functions/

You can also hire me or one of our developers to do this for your websites, just drop a mail to [email protected]

Advertisement







Autoload PHPFox – Access PHPFox From External PHP Scripts [How-To] was originally published on Digitizor.com on February 12, 2014 - 7:32 am (Indian Standard Time)