Calling variables from Stats.php in index.template.php.

Started by Daniel Marquard, January 26, 2007, 06:32:32 PM

Previous topic - Next topic

Daniel Marquard

I can't seem to call $context['num_hits'] in index.template.php, even with $context defined in the globals.  There are no parsing errors, and I'm sure it's correct, it's just that nothing is returned.  I believe the variable is defined in Stats.php, but I'm unsure how to include that in index.template.php.

B Patterson

That's because if you dump the $context variable, num_hits isn't calculated.  That's a big query, and it more than likely takes some time to get.

As for getting it into the $context var, you might want to find the query that's run to calculate the total hits (not sure which one it is) and then add that to perhaps your own file, include that in index.template.php and then use it.  Just a suggestion.

Also, I'd suggest removing the phpSysInfo and phpinfo(); links from your sig.  Lots of security info is relayed through those documents, some of which can get you into lots of trouble with hackers and DoS attacks.  Once again, just a suggestion.

Daniel Marquard

Quote from: bpat1434 on January 26, 2007, 07:55:40 PM
That's because if you dump the $context variable, num_hits isn't calculated.  That's a big query, and it more than likely takes some time to get.

As for getting it into the $context var, you might want to find the query that's run to calculate the total hits (not sure which one it is) and then add that to perhaps your own file, include that in index.template.php and then use it.  Just a suggestion.

Also, I'd suggest removing the phpSysInfo and phpinfo(); links from your sig.  Lots of security info is relayed through those documents, some of which can get you into lots of trouble with hackers and DoS attacks.  Once again, just a suggestion.

It's as simple as retrieving a number in the database, is it not?

I can see a hacker in search of my phpinfo in search of an exploitable version of PHP, though I fail to see any security risk with phpSysInfo.

B Patterson

QuoteI can see a hacker in search of my phpinfo in search of an exploitable version of PHP, though I fail to see any security risk with phpSysInfo.
IP address is visible, OS is visible, kernel is visible.  Lots of stuff that hackers can use for other things.  It's a personal thing, and just a suggestion.  You don't need to follow if you don't want to.

QuoteIt's as simple as retrieving a number in the database, is it not?
I didn't have the source in front of me at that time; however, I do now.  Basically, you'd want to execute the following query to get the number of hits for your forum:
SELECT SUM(hits) AS hits
FROM {$db_prefix}log_activity

Now, that will return one value.  That's cumulative hits.  You could also retrieve the MIN(date) and then get an average.  But basically, I looked in Stats.php in the Sources directory, then looked at the query around line 98.  Seems to do what you want.  Just add that where you need it.  The best place it seems to me would be BoardIndex.php.

Daniel Marquard

Quote from: bpat1434 on January 26, 2007, 11:41:18 PM
IP address is visible, OS is visible, kernel is visible.  Lots of stuff that hackers can use for other things.  It's a personal thing, and just a suggestion.  You don't need to follow if you don't want to.

You're 100% right regrading the OS and kernel; however, my IP can be retrieved with or without phpSysInfo.  :)

QuoteSELECT SUM(hits) AS hits
FROM {$db_prefix}log_activity

Now, that will return one value.  That's cumulative hits.  You could also retrieve the MIN(date) and then get an average.  But basically, I looked in Stats.php in the Sources directory, then looked at the query around line 98.  Seems to do what you want.  Just add that where you need it.  The best place it seems to me would be BoardIndex.php.

Good enough.  Thanks.  :)

B Patterson


Advertisement: