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 04-16-2009, 01:48 AM
larry_wic larry_wic is offline
 
Join Date: Jul 2005
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default how to execute php code in the vb template

I've seen the link to the functions you can run, using the < if condition> tags, etc.

i saw somethign about a plugin (i was confused on that)

I don't see / understand how you do this?
I run this little code on all my pages, as i want to track how they got to my pages
[[ yes, i use other log analyzers, other track analytic software, but i have a specific reason why i need this too]]

so I do get how i could use the if condidtion tags to do this?
i can't call the script / include it -- as i loose the refer data.
i'm pretty sure i need to run it ASAP as the visitor lands on the page.

Code:
session_start();
 if (empty($_SESSION['vREFERER'])) {
$vREFERER = $_SERVER['HTTP_REFERER']; 
session_register('vREFERER'); }
so anyone know how, where i could run this php code in the vb template?

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

As you've found out, raw PHP cannot be run inside templates. PHP must be run in plugins.

The Plugin Manager
Reply With Quote
  #3  
Old 04-16-2009, 02:54 AM
TigerC10's Avatar
TigerC10 TigerC10 is offline
 
Join Date: Apr 2006
Location: Austin, TX
Posts: 616
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You can use PHP, but the template manager restricts what PHP you can use to these functions:
  • in_array
  • is_array
  • is_numeric
  • isset
  • empty
  • defined
  • array
  • can_moderate
  • can_moderate_calendar
  • exec_switch_bg
  • is_browser
  • is_member_of

http://www.vbulletin.com/docs/html/f...n_conditionals



If you need something other than that, you'll have to do what Dismounted said and use a plugin.
Reply With Quote
  #4  
Old 04-16-2009, 03:06 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That PHP is only allowed in conditionals, and no where else.
Reply With Quote
  #5  
Old 04-16-2009, 03:55 AM
larry_wic larry_wic is offline
 
Join Date: Jul 2005
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

so i can't do this:

Code:
<if condition="session_start()">
 if (empty($_SESSION['vREFERER'])) {
$vREFERER = $_SERVER['HTTP_REFERER']; 
session_register('vREFERER'); }
</if>
you can tell, i don't get it
Reply With Quote
  #6  
Old 04-16-2009, 04:35 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No, you can't do that. You must add a plugin to do what you want - I have already posted a link to the manual. Read it.
Reply With Quote
  #7  
Old 04-16-2009, 05:02 AM
TigerC10's Avatar
TigerC10 TigerC10 is offline
 
Join Date: Apr 2006
Location: Austin, TX
Posts: 616
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You can do this...

Code:
<if condition="empty($_SESSION['vREFERER'])">
Referrer: $_SERVER['HTTP_REFERER']
</if>
You can check if something is empty, but you can't assign new variables and you can't register anything...
Reply With Quote
  #8  
Old 04-16-2009, 05:34 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That wouldn't work - the quotes would fail. Also, I don't know if you can access superglobals in templates directly (they may be cleared, or it might be at some other point, I don't remember).
Reply With Quote
  #9  
Old 04-16-2009, 06:00 AM
vbplusme vbplusme is offline
 
Join Date: Sep 2008
Location: CyberSpace
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You should take a look at the plugin section of the vBulletin manual to check out plugins and how they work. The architecture is a little strange at first but once you figure out the order, you can do a lot with it, including what you are trying to do I think.

http://www.vbulletin.com/docs/html/main/plugin_system
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 09:39 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.03788 seconds
  • Memory Usage 2,237KB
  • Queries Executed 13 (?)
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
  • (3)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)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