PDA

View Full Version : Displaying ip address of user


Duckface
06-04-2015, 02:12 PM
{vb: raw bbuserinfo.ip}

The above displays an empty string, what is the variable name exactly or isn't there one?

Additionally, this doesn't work either:


{vb:rawphrase ip}

MarkFL
06-04-2015, 02:20 PM
In a plugin (with appropriate hook location), you could use the statement:

$useripaddress = $_SERVER['REMOTE_ADDR'];

and then register that variable for the template in which you wish to use it.

To which template are you trying to add it, and I can help further. :D

Duckface
06-04-2015, 02:22 PM
Which hook location would you recommend? As it's for a custom page that I made http://spawnscape614.co.uk/forums/donate/donate.php

MarkFL
06-04-2015, 02:25 PM
Which hook location would you recommend?

I edited my post above...to which template are you trying to add the user's IP?

Duckface
06-04-2015, 02:30 PM
The template is a custom template called Donate.

MarkFL
06-04-2015, 02:38 PM
Okay, for your plugin, try the hook location "global_start" (since I don't know if there are any custom hook locations associated with this template) and let's try this instead for the PHP code:

if (THIS_SCRIPT === 'donate')
{
$show['userip'] = $_SERVER['REMOTE_ADDR'];
}

Then, in your template, use {vb:raw show.userip}. Let me know if this works. :D

Duckface
06-04-2015, 02:49 PM
Strangely not as logical as it sounds... I even tried (in the template):

<?php

echo($_SERVER['REMOTE_ADDR']);

?>

And still nothing.

MarkFL
06-04-2015, 02:55 PM
What PHP version are you using?

Duckface
06-04-2015, 02:55 PM
5.5.42-cll

MarkFL
06-04-2015, 03:01 PM
What I suggested should work...don't know why it's not. Maybe someone else can suggest another solution. :D

Duckface
06-04-2015, 03:04 PM
No worries man, thanks for your help. It should work...

kh99
06-04-2015, 05:10 PM
Strangely not as logical as it sounds... I even tried (in the template):

<?php

echo($_SERVER['REMOTE_ADDR']);

?>

And still nothing.

I think that probably didn't work for you because you can't do that in a template.

I think you should really use the defined constant IPADDRESS, because it's been checked to make sure it contains an ipaddress and not something else (that you're then going to display), and also it uses the proxy settings to display the user's ip address instead of the proxy (if that applies to you).

Anyway, one possible reason for Mark's code not working would be if you're not setting THIS_SCRIPT to 'donate' in your custom script. If you have a custom php file, then you must be creating and rendering the template in there? Then instead of using a plugin you could edit your donate.php and add code to register the ip address to the template. I can't give you the exact code for that without seeing donate.php, but maybe you can figure it out if you look at donate.php. It would be something like this (with the create and render calls already existing in your code):

$templater = vB_Template::create('Donate');
// You might have other calls to register here
$templater->register('userip', IPADDRESS);
$templater->render();

Then in the template you'd use {vb:raw userip}.

If you don't want to change donate.php then you should be able to use a plugin like Mark suggested. Do you have a line something like
define('THIS_SCRIPT', 'donate');

in donate.php?