Displaying HTTP referrer IP address in a post

Get help developing custom BBCodes or request one.
Post Reply
alanadams
Registered User
Posts: 12
Joined: Sun Aug 12, 2012 2:47 am

Displaying HTTP referrer IP address in a post

Post by alanadams » Thu Aug 09, 2018 1:00 am

I want to be able to post a message where a specific line of text will display the visitor's public IP address for them.

I've already "solved" this with a custom BBCode which has replacement text defined as:

Code: Select all

<script type="application/javascript">
  var http_referrer_ip = '(unknown)';
</script>

<script type="application/javascript">
  function getIP(json) {
    http_referrer_ip = json.ip;
  }
</script>

<script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"></script>

<script type="application/javascript">document.write( '' + http_referrer_ip + '' );</script>
The drawback here is that it's depending on the visitor's web client calling the external api.ipify.org service. Which I don't mind philosophically or technically on its own. And for as little as I intend to use this, it will be perfectly up to the task if there isn't a better solution.

What's nagging at me is "I'm using an external service to find an answer that phpBB itself already knows."

I don't expect there is already something ready-made like an already existing token symbol that could be referenced in the BBCode. But is there a way to invoke some PHP or JQuery from within a BBCode, or any other method that could retrieve the data sessions.php saved as "session->ip", or maybe access "$_SERVER['REMOTE_ADDR']" directly as part of the BBCode's output?

The answer may in fact be obvious; I'm just not familiar with phpBB or PHP to already know whether it's obvious or not.

Thanks.

EDIT: Some changes to the JavaScript that became necessary to support IE11.

User avatar
david63
Jr. Extension Validator
Posts: 14757
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Displaying HTTP referrer IP address in a post

Post by david63 » Thu Aug 09, 2018 6:34 am

You should be able to retrieve it by $request->server['HTTP_REFERER']
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

alanadams
Registered User
Posts: 12
Joined: Sun Aug 12, 2012 2:47 am

Re: Displaying HTTP referrer IP address in a post

Post by alanadams » Thu Aug 09, 2018 4:03 pm

Thanks. That looks like either PHP or JQuery... how exactly am I expecting to reference it from the context of the BBCode "replacement text" setting in ACP of phpBB 3.2.2?

Putting this literally into the "replacement text" resulted in the display of literally "$request->server['HTTP_REFERER']", presumably as expected. Using it from within a JavaScript tag (thinking it could be valid JQuery) resulted in the JavaScript debugger saying that the "->" symbol onward was "unexpected token".

Code: Select all

<script type="application/javascript">document.write( '' + $request->server['HTTP_REFERER'] + '' );</script>

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51349
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Displaying HTTP referrer IP address in a post

Post by Brf » Thu Aug 09, 2018 4:05 pm

Why would you want to display the viewing user's IP in a post he is reading? Why would you want the other users to be able to pepper their posts with such Javascript calls?

User avatar
3Di
Registered User
Posts: 12949
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Displaying HTTP referrer IP address in a post

Post by 3Di » Thu Aug 09, 2018 4:21 pm

This is a request, why should it be contested?
In my personal opinion, if I may express it, every request is legitimate if it is expressed in the proper manner. :)
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

alanadams
Registered User
Posts: 12
Joined: Sun Aug 12, 2012 2:47 am

Re: Displaying HTTP referrer IP address in a post

Post by alanadams » Thu Aug 09, 2018 4:27 pm

Brf wrote:
Thu Aug 09, 2018 4:05 pm
Why would you want to display the viewing user's IP in a post he is reading? Why would you want the other users to be able to pepper their posts with such Javascript calls?
Thanks Brf, that sounds like an additional good justification for making this into a local JQuery/PHP query rather than using the external service.

But the question remains, how to retrieve this information from phpBB's existing session data, from the context of the "replacement text" of a BBCode definition?

Post Reply

Return to “Custom BBCode Development and Requests”

Who is online

Users browsing this forum: No registered users and 5 guests