Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

18.2.14

Facebook group posts on own webpage in PHP

A friend needed his FB groups posts embedded on his webpage so here are some snippets that I don't forget :D
  1. At https://developers.facebook.com create a new APP, after creating you get the required ID and SECRET.
  2. From https://github.com/facebook/facebook-php-sdk download the PHP SDK

require_once(WB_PATH."/include/facebook/src/facebook.php"); // Get from https://github.com/facebook/facebook-php-sdk

$APP_ID = 'APPID';
$APP_SECRET = 'APPSECRET';
$GROUP_ID = 'GROUPID';

$config = array(
    'appId' => $APP_ID,
    'secret' => $APP_SECRET,
    'fileUpload' => false,
    'allowSignedRequest' => false,
);

$facebook = new Facebook($config);
extract($facebook->api("/$GROUP_ID/feed?limit=10"));

$posts = '';
foreach ($data as $d) {
    if (!empty($d['message'])) {
        $posts .= '
  • '.date('d.m.Y H:i', strtotime($d['created_time'])).'

    '.$d['message'].'

  • '; } }

    During googling I found http://pastebin.com/LPnzUQSF, but I didn't try.

    16.2.14

    Some PHP security goodness, how-to

    Some of my best practites for PHP

    1. Check the syntax of all of the php files:
    localhost:~ $ find $(pwd) -name \*.php -exec php -l '{}' \;
    

    2. Set php.ini for development:
    error_reporting=8192
    display_errors=On
    display_startup_errors=On
    log_errors=On
    error_log=error_log
    report_memleaks=On
    expose_php=On
    asp_tags=Off
    

    3. Watch out for proper type handling:
    $clean_int = (int)$dangerous_int;
    
    4. Watch apache/error_log for errors while running a link checker on the site (try also for authenticated user):
    tail -f /var/log/apache2/error_log
    
    More resources:
    http://blackhatlibrary.net/PHP http://www.phptherightway.com/