vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Cant get user's IP address when calling a script from a plugin (https://vborg.vbsupport.ru/showthread.php?t=327688)

cronjob78 12-03-2019 03:06 PM

Cant get user's IP address when calling a script from a plugin
 
I have a plugin that displays events from another part of my website unrelated to vBulletin. I want to write each information about each time an event is displayed to a database table and include the user's IP address in the data.

I'm adding the plugin as "global_start" and calling a variable called $show_event in my template files. In the plugin code I assign $show_event = implode('', 'www.mywebsite.com/forums/event.php');

$_SERVER['REMOTE_ADDR'] gives me my server's IP rather than the user's IP because of the way vBulletin calls up the plugins. I need the user's IP.

I note that plugins using "style_fetch" as the hook location use $_SERVER['REMOTE_ADDR'] successfully, but I have to use "global_start".

I can't access any global variables from event.php. If anyone can suggest anything I'd appreciate it.

Dave 12-03-2019 03:12 PM

If the script is visited as expect in a browser then the proper IP should always be present in $_SERVER['REMOTE_ADDR'], unless you use some sort of proxy. Can you access the IPADDRESS or ALT_IP constants?

cronjob78 12-05-2019 10:08 AM

Thanks for the reply Dave. I have solved the problem.


For years, using this code in the plugin window, had worked fine for me:

Code:

$var = implode('', file('path/to/this/file/myfile.php1'));
and I then included $var in my template, where I wanted the content of my PHP file to appear.
However, when you try to access the $_SERVER['HTTP_USER_AGENT'] in that PHP file it will return the results of the server's IP rather than that of the client IP.

However, if you use this code for your plugin instead:

Code:

ob_start();
  include('path/to/this/file/myfile.php');
  $includedphp = ob_get_contents();
  ob_end_clean();

$_SERVER['HTTP_USER_AGENT'] will return the user's IP correctly.

Dave 12-05-2019 10:12 AM

Ah that makes more sense. Yes, you'd have to do it like that.


All times are GMT. The time now is 10:39 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01019 seconds
  • Memory Usage 1,717KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete