?
Solved

Pulling Online Users

Posted on 2014-08-22
2
Medium Priority
?
113 Views
Last Modified: 2014-08-22
This is a continuation from this question: http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28502915.html

I've pulled the total members and total posts successfully but unable to get the current members online.

Here is the current code, but returns nothing:
//Get current stats from SCB
$page = file_get_contents("http://forums.starcitizenbase.com");
preg_match_all("/<span class='value'>([\d,]*)<\/span>/", $page, $match);
//var_dump($match);
$total_post = $match[0][0];
$total_member = $match[0][1];
$total_online = preg_match_all("/<h4 class='statistics_head clearfix'>([\d,]*)<\/h4>/", $page, $match);
echo 'total online: '.$total_online;
0
Comment
Question by:Nathan Riley
2 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 40279126
Please see a continuation of the theme: http://iconoun.com/demo/temp_nathan_riley.php

Moving parts are near line 88.  Note that there may be other counts of users doing stuff; I just look for the users online today.

<?php // /demo/temp_nathan_riley.php
error_reporting(E_ALL);

// SEE http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28502915.html

// A CURL FUNCTION WRAPPER
// A FUNCTION TO RUN A CURL-GET CLIENT CALL TO A FOREIGN SERVER
function my_curl
( $url
, $timeout=5
, $error_report=TRUE
)
{
    $curl = curl_init();

    // HEADERS AND OPTIONS APPEAR TO BE A FIREFOX BROWSER REFERRED BY GOOGLE
    $header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    $header[] = "Cache-Control: max-age=0";
    $header[] = "Connection: keep-alive";
    $header[] = "Keep-Alive: 300";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Language: en-us,en;q=0.5";
    $header[] = "Pragma: "; // BROWSERS USUALLY LEAVE THIS BLANK

    // SET THE CURL OPTIONS - SEE http://php.net/manual/en/function.curl-setopt.php
    curl_setopt( $curl, CURLOPT_URL,            $url  );
    curl_setopt( $curl, CURLOPT_USERAGENT,      'Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0'  );
    curl_setopt( $curl, CURLOPT_HTTPHEADER,     $header  );
    curl_setopt( $curl, CURLOPT_REFERER,        'http://www.google.com'  );
    curl_setopt( $curl, CURLOPT_ENCODING,       'gzip,deflate'  );
    curl_setopt( $curl, CURLOPT_AUTOREFERER,    TRUE  );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE  );
    curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, TRUE  );
    curl_setopt( $curl, CURLOPT_TIMEOUT,        $timeout  );
    curl_setopt( $curl, CURLOPT_VERBOSE,        TRUE   );
    curl_setopt( $curl, CURLOPT_FAILONERROR,    TRUE   );


    // IF USING SSL, THESE MAY BE IMPORTANT
    curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, FALSE  );
    curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, FALSE  );
    curl_setopt( $curl, CURLOPT_SSLVERSION,     3      );

    // RUN THE CURL REQUEST AND GET THE RESULTS
    $htm = curl_exec($curl);

    // ON FAILURE
    if ($htm === FALSE)
    {
        // VISUALIZE ERROR MESSAGES
        if ($error_report)
        {
            $err = curl_errno($curl);
            $inf = curl_getinfo($curl);
            echo "CURL FAIL: $url TIMEOUT=$timeout, CURL_ERRNO=$err";
            var_dump($inf);
        }
        curl_close($curl);
        return FALSE;
    }

    // ON SUCCESS RETURN XML / HTML STRING
    curl_close($curl);
    return $htm;
}

// READ FROM THE URL
$url = 'http://forums.starcitizenbase.com/';
$htm = my_curl($url);

// PARSE THE WEB PAGE CONTENT
$sig = "<div id='board_stats'>";
$arr = explode($sig, $htm);
$sig = '</div>';
$arr = explode($sig, $arr[1]);
$str = strip_tags($arr[0], '<span>');

$sig = "<span class='value'>";
$arr = explode($sig, $str);

// GET POSTS AND MEMBERS
$p = preg_replace('/[^0-9,]/', NULL, $arr[1]);
$m = preg_replace('/[^0-9,]/', NULL, $arr[2]);

// SHOW THE WORK PRODUCT
echo "POSTS: $p, MEMBERS: $m, ";

// FIND USERS ONLINE
$sig = 'users are online';
$arr = explode($sig, $htm);
$str = substr($arr[0], -10);
$str = preg_replace('/[^0-9,]/', NULL, $str);
echo "ONLINE: $str";

Open in new window

0
 
LVL 12

Author Comment

by:Nathan Riley
ID: 40279376
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question