vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Plugins and Agents and Scripts, Oh my... (https://vborg.vbsupport.ru/showthread.php?t=196315)

David LeBow 11-15-2008 05:27 AM

Plugins and Agents and Scripts, Oh my...
 
And I thought that I was trying something simple...

I have a little plugin, short and stout:

PHP Code:

$Rotatordata file_get_contents('http://www.MySite.Com/Rotator.asp'); 

The output of the asp page gets inserted in the header template like this:

PHP Code:

$Rotatordata 

It's some custom ad rotator logic. Works like a charm. Then I thought I'd get clever and query the HTTP User Agent within the ASP's VBScript, something like this:

sAgent = Request.ServerVariables ("HTTP_USER_AGENT")

I'd like to disregard requests from web crawlers. If I request Rotator.asp from the browser, everything's fine. Once I embed it as shown above into the PHP Scripting and template in vBulletin, sAgent always returns an empty string.

Googling, I stumbled on this, but don't know to what extent it's true:
"file("yoururl"); will read the page and send an empty UA [User Agent] by default, this is sometimes done to filter your page, remove javascript, flash or java."
I expect that file and file_get_contents act in a similar way in this regard (?).

My question: is there any way to get at the user agent within the asp within the plugin called by PHP script within the VBulletin template?

Thanks in advance for any input.

Dismounted 11-15-2008 09:15 AM

Add a GET variable to the end of the URL string appending the UA, maybe?

David LeBow 11-15-2008 01:30 PM

Thanks for the prompt reply. I'm afraid I don't see what you're suggesting, though.

Within the ASP the syntax is correct and works fine outside of the scripted PHP VBulletin environment. It seems as if the environment available when processing the ASP doesn't give access to the request elements (?) somehow.

:confused:

Dismounted 11-17-2008 04:00 AM

Exactly - so pass the variable from within PHP onto the ASP application (e.g. as a GET variable on the end of the URL).

David LeBow 11-17-2008 06:28 AM

...the light slowly dawns, even on me.

Last bonus question (honest) - do you happen to know the vBulletin / PHP syntax of the user agent from within a header template? I've been coding all manner of things for years, but have had PHP foisted on me to support the forum.

Thanks from the other side of the planet.

Dismounted 11-17-2008 08:48 AM

PHP Code:

$_SERVER['HTTP_USER_AGENT'

Keep this page for reference: http://www.php.net/manual/en/reserve...les.server.php.

David LeBow 11-17-2008 11:35 AM

Superb.

It took a bit more tweaking than I thought, but for anyone who cares, the final plugin code looks like this:

PHP Code:

$UserAgent $_SERVER['HTTP_USER_AGENT'];
$UserAgent str_replace(" ""%20"$UserAgent);
$Rotatordata file_get_contents('http://www.MySite.biz/Rotator.asp?UA=' $UserAgent); 

the ASP page can read the user agent like this:

sAgent = Request.QueryString ("UA")

and all is right with the world.

Thanks for your help!

Dismounted 11-18-2008 03:27 AM

Instead of doing a S&R on the string, use rawurlencode(). I'm sure ASP has a "reverse" function.


All times are GMT. The time now is 06:24 AM.

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.00956 seconds
  • Memory Usage 1,729KB
  • 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
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)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