WordPress.org

Ready to get started?Download WordPress

Forums

ShortStat problems.. (PHP Script) (13 posts)

  1. MatthewRobertson
    Member
    Posted 9 years ago #

    I downloaded and installed Shaun Inman's Shortstat (found here).

    Everything worked perfectly. The trackme.php page (which tests if the code works) worked perfectly.

    The problem was implementing.

    The author said to implement
    <?php @include_once($_SERVER["DOCUMENT_ROOT"]."/shortstat/inc.stats.php"); ?>
    into any pages wishing to be tracked.

    Okay. So I put this in the header.php via WP 1.5's Theme Editor. Logic said that putting the code in header.php would make the code go on all pages.

    The problem was the code didn't work.
    If you visited the test page, it recorded the visit.
    If you visited a normal PHP page (without WP), it recorded the vist.
    But any pages built via WP did not record the visit.

    The code was inserted correctly. I put an echo in the code, and it echoed back on all pages. If it echoes correctly, shouldn't it track correctly?

    It doesn't.

    Does WP allow scripts to run (with MySQL functions and what have you) in 'themes'? Because it's got something to do with WP.

    ~~~

    Try it yourself (prove me wrong please)

    1. Visit my ShortStat site (You will have to type the address in manually: www.bugger.3rror.com/shortstat/)

    2. Visit trackme.php (its a simple php page with the tracking code on it.)

    3. Go back to my ShortStat site (www.bugger.3rror.com/shortstat/). It should have recorded your visit.

    4. Now go to a WP page, say the home page or a perma link. This has the same code as the trackme page.

    5. Go back to my ShortStat page (www.bugger.3rror.com/shortstat/). Did it record your visit? When I do it, it doesn't.

    What's wrong?

  2. Don't add it to the header. Add it to the footer instead. Place it in footer.php right after the sentence or last word and before <div id="footer"> closes.

    Though, I wouldn't recommend Shortstat as it hasn't improved much for quite a while (a few bug fixes and tiny features here-and-there). IMO, BAStats (a WordPress plugin) looks more promising.

    http://www.asymptomatic.net/archives/2005/02/14/1307/ba-stats/
    Download: http://asymptomatic.net/wp-hacks

  3. MatthewRobertson
    Member
    Posted 9 years ago #

    Thanks.

    Would you mind explaining why I should put it in the footer (for future references)?

  4. Well, the header controls how your posts are displayed and how the rest of the theme is accessed. So, the going opinion is to not mess with the header unless you're really confident in what you're doing, and you could have easily put the ShortStat code in a position that would have prevented it from working. The footer, on the other hand, is expendable (easy to fix) and is displayed on every page (in most themes). Similarly, all active WP plugins "hook" into either the footer or the sidebar.

  5. MatthewRobertson
    Member
    Posted 9 years ago #

    Sorry, but it doesn't seem to be working.

    I've placed it all over the footer.php but no luck.

    I don't understand why. It calls the script and everything. It just doesn't "record the visit."

    What can I do?

    On your suggestion to BAstats, I just want a simple one for now. Shaun Inman's was promising and looks slick. I still would like to use it.

  6. Well, I can tell you that it's not a problem with WordPress. I have both PHP code (with MySQL functions) and javascript code in my footer. You'll have to talk to the developer some more.

  7. serif
    Member
    Posted 9 years ago #

    I am having the same problem as Mathew. Finally got Shortstat working (after fixing some IIS issues), and the _trackme.php does it's job perfectly. Have tried adding the Shortstat code into my WP site though and no results come through. Have tried adding it into the header, footer, index.jsp etc. but no luck. Anyone else out there had this problem and fixed it?

  8. jehiah
    Member
    Posted 9 years ago #

    Two comments.

    In your configuration.php you need to turn logging on.

    change the 'false' to 'true' in the last line

    $shortstat = true;

    Second, it doesn't matter if you put the include in your header or footer. It would matter if the logging required a separate page request from the client (like including an image in the page), but it doesn't. Shortstat is entierly server side, and will not display to your page, so no need to wrap it in a div block and put at the end of the page.

    As for ShortStats not being improved, I have a sweet plugin that i've added. Just drop a few files into your shortstats folder and check it out. (end shameless plug)

    Pathstats - ShortStat plugin

  9. jennmiller
    Member
    Posted 9 years ago #

    jehiah, that is indeed a SWEET addition.

  10. serif
    Member
    Posted 9 years ago #

    Matthew - is your site hosted on an IIS server? If so there are a few workarounds that need to be made for shortstat to work nicely. I've just managed to get it going (finally!). For anyone else interested, it turns out that $_SERVER['DOCUMENT_ROOT'] and $_SERVER['REQUEST_URI'] used in Shortstat aren't supported on IIS. To get it working I had to change the call to the include file to be:

    if(!isset($_SERVER['DOCUMENT_ROOT'])) {
    $_SERVER['DOCUMENT_ROOT'] = substr($_SERVER['PATH_TRANSLATED'],0,strlen($_SERVER['SCRIPT_NAME']) * - 1);
    }

    And in the Shortstat include file itself I needed to change:

    $res = $_SERVER['REQUEST_URI'];
    to be
    $res = $_SERVER['SCRIPT_NAME'];

    Hope this is useful for someone. It drove me nuts for a while.

  11. ralph
    Member
    Posted 9 years ago #

    @serif: Firstly, the script works - it just doesn't work with WP.
    If you have the same problem, and you solved it above, could you explain in detail how you did, please?

  12. Ralph, I'm using ShortStat with no problems. I put the ShortStat call at the top of the main index.php (in the wordpress directory).

  13. serif
    Member
    Posted 9 years ago #

    Hi Ralph. I did the same as macmanx and put the include right at the top of my index.php file. This seemed to work, but for some reason if I tried putting it in the header or footer it didn't. No idea why. The only changes I made to the shortsat code were the ones I mentioned above, and one other concerning page references, but these were due to the server my site is on.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.