Reading the session ip address inside template file

Discussion forum for MOD Writers regarding MOD Development.
Locked
techman41973
Registered User
Posts: 410
Joined: Thu Mar 28, 2013 10:27 pm

Reading the session ip address inside template file

Post by techman41973 » Sat Dec 27, 2014 3:09 am

I'm using Mouseflow video analytics in my phpbb forum, which works by adding specifc javascript code in my footer template.
With limitations on the number of sessions I can record per month, I only want to enable for visits from specific ip addresses.
Is there a way to read or test the ip address of the session from inside a template file?
Then I could do something like this

<!-- IF SESSION_IP = 'XXX' or SESSION_IP = 'XXX' -->
-- Mouseflow analytics code ---
<!-- ENDIF -->

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: Reading the session ip address inside template file

Post by RMcGirr83 » Sat Dec 27, 2014 1:52 pm

You could use something like this within the page_header function of the includes/functions.php file

Code: Select all

'S_USER_IP' => ($user->data['user_ip'] == xxx.xxx.xxx.xxx) ? true : false,
then use the switch in your html file like

<!-- IF S_USER_IP -->

if you wanted to use an array the code for the functions file would be something like this which would go above the $template->assign_vars

$check_ip = array('xxx.xxx.xxx.xxx', 'xxx.xxx.xxx.xxx');

then the switch would be

Code: Select all

'S_USER_IP' => in_array($user->data['user_ip'], $check_ip) ? true : false,
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

techman41973
Registered User
Posts: 410
Joined: Thu Mar 28, 2013 10:27 pm

Re: Reading the session ip address inside template file

Post by techman41973 » Sun Dec 28, 2014 6:29 am

Thank you. I tried your 1st method, but it didn't work without enclosing the ip address between ' '
I also tried your 2nd method as instructed, added to viewtopic.php since I'm checking the variable in viewtopic_body.html
Doesn't work for me

Locked

Return to “[3.0.x] MOD Writers Discussion”