dropbox1111 2016-04-21 20:10
浏览 186
已采纳

将PHP变量传递到嵌入在IFRAME中的另一个PHP文件

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:

<?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...

  • 写回答

1条回答 默认 最新

  • duanji6997 2016-04-21 20:32
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?