Announcement

Collapse
No announcement yet.

Inserting a PHP function in the header.php

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Forum] Inserting a PHP function in the header.php

    Hello everyone,

    I have a seemingly basic question that I halfway answered for myself by doing some searching. I would post this on vb.org except I think it's more a quesstion about a workaround for built in vbul functions than a possible modification.

    Code:
    <?php print(Date("l F d, Y")); ?>

    I was trying to insert a php function that displays today's date in the header, but the simple php print function and other formats did not work. I was a tad perplexed until I found that there are black listed php functions for security reasons. https://www.vbulletin.com/docs/onepage/#item113 I totally accept that this is necessary, but that still leaves me with the need to put today's date and time in the header.

    Can anyone recommend anything along those lines?

  • #2
    You cannot use PHP directly within the templates. That page you're referring shows some functions we include for conditional use only. You would have to create a plugin that parses the time output, assigns it a variable, registers the variable for the header and then you can add the variable to the template.

    If you need help with customizations of this sort, you should visit www.vbulletin.org.

    You can however use Javascript in a template and use that to output the time for the user but it will use the time their computer is set to, not the server time. Probably less confusing. Something like this:
    http://www.codingforums.com/archive/.../t-153468.html
    Translations provided by Google.

    Wayne Luke
    The Rabid Badger - a vBulletin Cloud demonstration site.
    vBulletin 5 API

    Comment


    • #3
      Originally posted by Wayne Luke View Post
      You cannot use PHP directly within the templates. That page you're referring shows some functions we include for conditional use only. You would have to create a plugin that parses the time output, assigns it a variable, registers the variable for the header and then you can add the variable to the template.

      If you need help with customizations of this sort, you should visit www.vbulletin.org.

      You can however use Javascript in a template and use that to output the time for the user but it will use the time their computer is set to, not the server time. Probably less confusing. Something like this:
      http://www.codingforums.com/archive/.../t-153468.html
      Great thanks for the reply.

      I think I'm going to go the PHP route. I have done something similar about 5 years ago when I first installed vbulletin, I'm a bit rusty, but I remember needing to include a call to an external script in the header. Here I am guessing I will just create a php file with the date function inside, then make a reference to it like you said.

      https://www.vbulletin.com/forum/show...P-or-HTML-File

      Incidentally, 5 years later I upgraded to vb4, those old calls to that plugin was still enabled somehow and were creating failed requests in the header. I pulled my hair out trying to figure out why, forgetting about the old call to the external script.

      I'd do it the easier javascript way, but I'm looking for a way that is non-js so that SE's will see it.

      Thanks for the info.

      Much obliged.

      Comment


      • #4
        You need to register variables before they can be shown in a template when using vBulletin 4.X. This article should give insight on this: http://www.vbulletin.org/forum/showthread.php?t=228078
        Translations provided by Google.

        Wayne Luke
        The Rabid Badger - a vBulletin Cloud demonstration site.
        vBulletin 5 API

        Comment

        widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
        Working...
        X