Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 11-15-2008, 05:27 AM
David LeBow David LeBow is offline
 
Join Date: Aug 2008
Location: Switzerland
Posts: 38
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 11-15-2008, 09:15 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Add a GET variable to the end of the URL string appending the UA, maybe?
Reply With Quote
  #3  
Old 11-15-2008, 01:30 PM
David LeBow David LeBow is offline
 
Join Date: Aug 2008
Location: Switzerland
Posts: 38
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.

Reply With Quote
  #4  
Old 11-17-2008, 04:00 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Exactly - so pass the variable from within PHP onto the ASP application (e.g. as a GET variable on the end of the URL).
Reply With Quote
  #5  
Old 11-17-2008, 06:28 AM
David LeBow David LeBow is offline
 
Join Date: Aug 2008
Location: Switzerland
Posts: 38
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

...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.
Reply With Quote
  #6  
Old 11-17-2008, 08:48 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$_SERVER['HTTP_USER_AGENT'
Keep this page for reference: http://www.php.net/manual/en/reserve...les.server.php.
Reply With Quote
  #7  
Old 11-17-2008, 11:35 AM
David LeBow David LeBow is offline
 
Join Date: Aug 2008
Location: Switzerland
Posts: 38
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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!
Reply With Quote
  #8  
Old 11-18-2008, 03:27 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:03 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04594 seconds
  • Memory Usage 2,231KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete