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 »

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
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Displaying HTTP referrer IP address in a post

Post by david63 »

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!

I now no longer support any of my extensions but they will start to become available here
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 »

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: 53400
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 »

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
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Displaying HTTP referrer IP address in a post

Post by 3Di »

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. :)
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
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 »

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”