www.webdeveloper.com
Results 1 to 6 of 6

Thread: show/hide recurring content based on server time

Hybrid View

  1. #1
    Join Date
    May 2010
    Posts
    3

    Arrow show/hide recurring content based on server time

    New here, and know nothing about PHP. But I believe PHP is what I need to accomplish this task.

    I need to show/hide some content (in my case a graphical button), based on a recurring weekly event. My client is doing a live streaming video cast every Thursday from 3-4. She wants a button to appear ("click here to tune in LIVE!") for just that duration of time. When her show is over at 4:00, the button disappears until the next Thursday at 3:00 (This is all in US Central Time).

    Of course I could do this manually each week, but that is inefficient and unreliable, so I'm looking for a way to automate this task.

    I have been searching for hours and have come up empty. The one thing that was closest was this thread:

    http://www.webdeveloper.com/forum/sh...d.php?t=103041

    which sounds like what I need to do, but it is using javascript instead of PHP. I would be fine with javascript, except that it uses the web visitor's computer clock, which could be inaccurate and doesn't handle the fact that vistors could be in a different time zone. I need it to be based on the server's clock instead.

    So, can anybody point me in the right direction using PHP to do this? Again, I know very little about PHP, so please be patient with me.

    Thanks in advance.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    22,284
    PHP Code:
    <?php
    if(date('l') == 'Thursday' and date('G') == 15) {
    ?>
    <button type="button" onclick="blah blah blah">
    <img src="click.png" alt="watch video" />
    </button>
    <?php
    }
    ?>
    If your server is not in the same time zone, you may want to first use date_default_timezone_set() to set the desired time zone.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    May 2010
    Posts
    3
    Thanks NogDog. I will see if this helps and report back either way. However, does this address the issue of having the button disappear when the show is over at 4:00? As mentioned, I don't know much about PHP, but I don't see anything in your code that appears to address that part. How can I set a duration, or expiration date?

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    22,284
    It will only show if the hour is 15 (3pm), so it will show from Thursday 15:00:00 until Thursday 15:59:59.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  5. #5
    Join Date
    May 2010
    Posts
    3
    Oh great, thanks! I'm so grateful for your help. Is there a way to be more specific though? The only reason I ask is because she has another show that starts on the half hour, 11:30 am -12:30 pm that she also wants to do this for. I assume the same code won't work for that one, without modifying it somehow...

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    22,284
    You might want to make a function that can be used for any case:
    PHP Code:
    <?php
    /**
     * Determine if current time is within specified weekday and time window
     * @return bool
     * @param string  $dayName       'Monday', 'Tuesday',...
     * @param int     $startHour     0-23
     * @param int     $startMinute   0-59
     * @param int     $endHour       0-23
     * @param int     $endMinute     0-59
     */
    function isInTimeWindow($dayName$startHour$startMinute$endHour$endMinute)
    {
       
    $dayName ucfirst($dayName);
       list(
    $dayNow$timeNow) = explode('|'date('l|Hi'));
       return (
          
    ucfirst($dayName) == $dayNow and
          
    $timeNow >= sprintf('%02d%02d'$startHour$startMinute) and
          
    $timeNow <= sprintf('%02d%02d'$endHour$endMinute)
       );
    }
    // Sample usage:
    if(isInTimeWindow('thursday'16301730))
    {
    ?>
    <button>Test</button>
    <?php
    }
    ?>
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.24578 seconds
  • Memory Usage 3,077KB
  • Queries Executed 13 (?)
More Information
Template Usage (30):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (27):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./includes/functions_threadedmode.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates