Pass PHP variable into another PHP file that is embedded in IFRAME

I have a page set up in wordpress that generates content based on various variables. It creates a string that is a URL to a Google calendar. Then, the Google calendar is embedded via iframe although the Google calendar is hosted on our domain. I can’t figure out how to get the string transferred into the iframe.
Here is the code:

  <?php if ( is_page('baseball') ) {
   $current_sport = 'Baseball';
   $athletic_calendar = get_field('calendar_baseball', 'option');
   $athletic_calendar_boys_varsity = get_field('boys_varsity_calendar_basketball', 'option');
   $athletic_calendar_girls_varsity = get_field('girls_varsity_calendar_basketball', 'option');
   $athletic_calendar_boys_jv = get_field('boys_jv_calendar_basketball', 'option');
   $athletic_calendar_girls_jv = get_field('girls_jv_calendar_basketball', 'option');
   $athletic_calendar_boys_freshmen = get_field('boys_freshmen_calendar_basketball', 'option');
   $athletic_calendar_girls_freshmen = get_field('girls_freshmen_calendar_basketball', 'option');
  }   ?>
   <?php $calendar_string = 'src=' . $athletic_calendar . '&';
   if ( $athletic_calendar_boys_varsity ) : 
   $calendar_string .= 'src=' . $athletic_calendar_boys_varsity . '&';
   endif; 
   if ( $athletic_calendar_girls_varsity ) : 
   $calendar_string .= 'src=' . $athletic_calendar_girls_varsity . '&';
   endif;
   if ( $athletic_calendar_boys_jv ) : 
   $calendar_string .= 'src=' . $athletic_calendar_boys_jv . '&';
   endif; 
   if ( $athletic_calendar_girls_jv ) : 
   $calendar_string .= 'src=' . $athletic_calendar_girls_jv . '&';
   endif;
   if ( $athletic_calendar_boys_freshmen ) : 
   $calendar_string .= 'src=' . $athletic_calendar_boys_freshmen . '&';
   endif;
   if ( $athletic_calendar_girls_freshmen ) : 
   $calendar_string .= 'src=' . $athletic_calendar_girls_freshmen . '&';
   endif; 
   global $gcal_string;
   $gcal_string = 'https://www.google.com/calendar/embed?' . $calendar_string . 'ctz=America/Chicago';
  ?>
   <?php echo '<iframe src="https://www.bmchs.org/gcal-custom.php" style="border-width:0" width="100%" height="685" frameborder="0" scrolling="no"></iframe>' ;?>

And then here is the code in gcal-custom.php:

Read More
<?php
 $content = file_get_contents('https://www.google.com/calendar/embed?src=bmchs.org_2i1q9e2a5o3ud6d9qji33a2reg%40group.calendar.google.com&ctz=America/Chicago');
 $content = str_replace('</title>','</title><base href="https://www.google.com/calendar/" />', $content);
 $content = str_replace('//calendar.google.com/calendar/static/2feb9b53c01cf3989b70175c72c580c5embedcompiled_fastui.css','https://www.bmchs.org/calendar.css', $content);
 echo $content; ?>

What I need to happen in the gcal-custom.php is this:

$content = file_get_contents( $gcal_string);

Is this possible? I can’t figure it out…

Related posts

1 comment

  1. you seem to build a GET – string with $calendar_string and $gcal_string, but you never use it in your iframe.

    your iframe‘s source is just a static string without any kind of variable:

    <iframe src="https://www.bmchs.org/gcal-custom.php" style="border-width:0" width="100%" height="685" frameborder="0" scrolling="no"></iframe>
    

    the variable values won’t get in there magically.

    why don’t you use the string you may have build for this exact purpose?

    <?php echo '<iframe src="https://www.bmchs.org/gcal-custom.php?' . $calendar_string . '"></iframe>'; ?>  
    

    then read the GET variables in gcal-custom.php; for example:

    <?php 
      $my_src = $_GET["src"];
    ?>
    

    another possibility would be to save your values into session variables and then read the values in the PHP file opened in the iframe.

Comments are closed.