Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 4 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
[vBulletin 4] Simple way of including an external PHP file
Crimm's Avatar
Crimm
Join Date: Feb 2007
Posts: 170

 

Show Printable Version Email this Page Subscription
Crimm Crimm is offline 05-12-2010, 10:00 PM

There are other articles out there on variables, templates, etc on vBulletin 4. This is a simple example of including an external PHP files like you used to be able to do here:

http://www.vbulletin.com/forum/showt...P-or-HTML-File

Thanks to this Blog post by David IB http://www.vbulletin.com/forum/entry...s-to-templates and this article by cellarius https://vborg.vbsupport.ru/showthread.php?t=228078

I have figured out it's only a simple extra step.

Step 1: Create a new plugin
  • Hook Location: What area of the forums you want this variable to appear. Don't know where? Use global_start
  • Title: Give it a title
  • Execution order: Your choice
  • Plugin PHP Code:

    Code:
    ob_start();
      require_once('LOCATION OF EXTERNAL FILE');
      $php_include = ob_get_contents();
    ob_end_clean();
    vB_Template::preRegister('TEMPLATE YOU ARE USING',array('php_include' => $php_include));

Step 2: You will have to figure out these two entries for yourself: LOCATION OF EXTERNAL FILE & Hook Location

To give you an example of what you should use is that if you want to display your external PHP file on your Forum's Home. Then replace these two with these values:

Hook Location with forumhome_start
TEMPLATE YOU ARE USING with FORUMHOME

Keep in mind that global_start will still be acceptable, but it's extra loading time where it's not needed. Therefore choosing the optimum hook location is better for your performance overall.

Step 3: Visit the Style Manager -> TEMPLATE YOU ARE USING and place the variable in your style where you want it. You will have to use the new format.

Code:
{vb:raw php_include}
That's it - Pretty simple; see?

Notes, If you want to:

Include this PHP file in multiple templates then preRegister it for the multiple templates:

Code:
vB_Template::preRegister('TEMPLATE YOU ARE USING',array('php_include' => $php_include));
vB_Template::preRegister('TEMPLATE YOU ARE USING 2',array('php_include' => $php_include));
Thanks to David IB again.

I'm still learning as I go with vb4, but if I learn some more notes to add... I'll drop by here.

I hope that helps some one out there!
Reply With Quote
  #32  
Old 01-02-2011, 03:45 PM
robert garrett robert garrett is offline
 
Join Date: Mar 2010
Posts: 9
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

o.k. I got that to work, now how to get scripts that call the same page to work?
Reply With Quote
  #33  
Old 01-14-2011, 07:17 PM
ehsanix ehsanix is offline
 
Join Date: Oct 2003
Posts: 154
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

woooooooooooooooooooooow
very nice
thanx
thanx man
gooood job
exelent
Reply With Quote
  #34  
Old 01-15-2011, 10:58 PM
ehsanix ehsanix is offline
 
Join Date: Oct 2003
Posts: 154
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How can I php file in my Sidebar include?
help
Reply With Quote
  #35  
Old 01-27-2011, 01:47 AM
MMODisneyForums MMODisneyForums is offline
 
Join Date: Jan 2011
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is a nice tutorial you have, I have read many, but this one is very clear and simple. But from all the tutorials I've tried, I can never get this to work. I want to have a php file output into the postbit_legacy template. So I made a plugin following this tutorial, using this:

Hook Location: global_start
Title: Testing
Execution Order: 5
And the PHP Code:
PHP Code:
ob_start();
 require_once(
'http://**********/creds.php');
  
$php_include ob_get_contents();
ob_end_clean();
vB_Template::preRegister('postbit_legacy',array('php_include' => $php_include)) 
Then in the postbit_legacy template I added in {vb:raw php_include} where it should go. Nothing shows up, and I get an error at the top of the page:
PHP Code:
Parse errorsyntax errorunexpected $end in /home/****/public_html/forums/global.php(29) : eval()'d code on line 7 
I get that error on pages that have posts on it. On the forum homepage, nothing shows up except:

PHP Code:
Parse errorsyntax errorunexpected $end in /home/mmodis/public_html/forums/global.php(29) : eval()'d code on line 7

Fatal error: Call to undefined function print_portal_output() in /home/mmodis/public_html/index.php on line 46 
If anyone can help me with this thanks, I have had problems with using plugins to include php files in the templates for too long. It always worked perfectly fine for me in vB 3.4. Thankyou for your time.

Note: Where the "****" are, just for posting the code here, I put those in to censor where the files are, just to be safe. I really do have the correct paths in the files uploaded to the site.
Reply With Quote
  #36  
Old 01-29-2011, 02:52 AM
risestar risestar is offline
 
Join Date: Oct 2001
Posts: 31
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well global_start hook location is now obsolete as of 4.0.3+ and 4.1. You should probably use the global_bootstrap_init_start hook instead if you are using a recent version. Also using $php_include as your variable might be causing problems so rename it to something unique. Your plugin code should probably be more like this

Code:

ob_start();
  require_once('http://www.xxxxxxx.com/creds.php');
  $creds = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('postbit_legacy',array('creds' => $creds));

and of course the call in the postbit_legacy template {vb:raw creds}


The parse error in your code is due to your missing the ";" at the end of your statement


Quote:
Originally Posted by MMODisneyForums View Post
This is a nice tutorial you have, I have read many, but this one is very clear and simple. But from all the tutorials I've tried, I can never get this to work. I want to have a php file output into the postbit_legacy template. So I made a plugin following this tutorial, using this:

Hook Location: global_start
Title: Testing
Execution Order: 5
And the PHP Code:
PHP Code:
ob_start();
 require_once(
'http://**********/creds.php');
  
$php_include ob_get_contents();
ob_end_clean();
vB_Template::preRegister('postbit_legacy',array('php_include' => $php_include)) 
Then in the postbit_legacy template I added in {vb:raw php_include} where it should go. Nothing shows up, and I get an error at the top of the page:
PHP Code:
Parse errorsyntax errorunexpected $end in /home/****/public_html/forums/global.php(29) : eval()'d code on line 7 
I get that error on pages that have posts on it. On the forum homepage, nothing shows up except:

PHP Code:
Parse errorsyntax errorunexpected $end in /home/mmodis/public_html/forums/global.php(29) : eval()'d code on line 7

Fatal error: Call to undefined function print_portal_output() in /home/mmodis/public_html/index.php on line 46 
If anyone can help me with this thanks, I have had problems with using plugins to include php files in the templates for too long. It always worked perfectly fine for me in vB 3.4. Thankyou for your time.

Note: Where the "****" are, just for posting the code here, I put those in to censor where the files are, just to be safe. I really do have the correct paths in the files uploaded to the site.
Reply With Quote
  #37  
Old 01-31-2011, 05:54 PM
MMODisneyForums MMODisneyForums is offline
 
Join Date: Jan 2011
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the help. I tried all of that, and now every page in the forum is completely blank when I turn the plugin on. If I turn it off the forums are back. Is there any reason for this?
Reply With Quote
  #38  
Old 01-31-2011, 06:46 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I still don't understand why you guys just don't use the require_once to include the file in the php hook right before the code you want to use it with. You are taking the long way around doing it this way. Unless you need the included file for every page, it makes no sense to put it in the global hook.
Reply With Quote
  #39  
Old 01-31-2011, 07:36 PM
risestar risestar is offline
 
Join Date: Oct 2001
Posts: 31
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What version of vbulletin are you using?

If you type in the script location directly from your browser, does it work? If not, then its a problem with your script.

Also, your php.ini might be set to disallow http php include calls, if you so need to enable it, or use the path call instead

Code:
ob_start();
  require_once('/path/to/your/website/creds.php');
  $creds = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('postbit_legacy',array('creds' => $creds));
Otherwise, its a typo, if you are using this code, make sure you cut and paste it, have the path/url correct



Quote:
Originally Posted by MMODisneyForums View Post
Thanks for the help. I tried all of that, and now every page in the forum is completely blank when I turn the plugin on. If I turn it off the forums are back. Is there any reason for this?
Reply With Quote
  #40  
Old 01-31-2011, 08:31 PM
MMODisneyForums MMODisneyForums is offline
 
Join Date: Jan 2011
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm using version 4.1.0. I tried changing my creds.php file to just simply echo "Test", and I still just get a plain white page on the forums. If I open the php file in my browser it correctly says Test. Should I change the hook location? Is there a better location for postbit_legacy? And I have copy pasted that code exactly in, and replaced the URL. What could be going wrong here? Thanks

Edit: I have noticed something else that is interesting. If I remove the {vb:raw creds} from the postbit_legacy template, there is still a blank page. If the plugin is on, theres a blank page, even if its not being called from the template. Hope this helps.
Reply With Quote
  #41  
Old 02-02-2011, 02:48 AM
risestar risestar is offline
 
Join Date: Oct 2001
Posts: 31
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The plugin is fairly straight forward, as long as you have a valid script that you are calling and your plugin code is valid, you should be good to go.

you might have a php.ini config issue going on.

Create a new file in your forum root, call it test.php

Insert this

<?php include ("/server/path/to/your/test.php"); ?>

<?php include ("http://www.yoursite.com/forum/test.php"); ?>

/insert this

Then open the test.php in your browser

If they BOTH work, you should have your echoed text inserted twice. If only ONE works, or you get a php error, you have a php.ini config issue to work out.
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 05:09 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.05855 seconds
  • Memory Usage 2,352KB
  • Queries Executed 28 (?)
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
  • (5)bbcode_code
  • (6)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (7)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)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_postinfo_query
  • fetch_postinfo
  • 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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete