【问题标题】:Embedded iframe URL to include current user id in wordpress [closed]嵌入 iframe URL 以在 wordpress 中包含当前用户 ID [关闭]
【发布时间】:2016-04-30 12:39:47
【问题描述】:

我在我的 wordpress 页面上嵌入了以下 URL 作为 iframe,其中包含以下代码:

<iframe src="https://cpalead.com/mobile/locker/?pub=195930&gateid=985632&subid=$user" height="100%" frameborder="0" name="iframetarget" id="iframetarget"></iframe>

我的页面模板已经定义了 $user 参数如下:

$user = get_current_user_id();

但是,当我的页面加载 iframe 时,URL 源是这样的:

https://cpalead.com/mobile/locker/?pub=195930&gateid=985632&subid=$user

它不会将 $user 变量传递给 iframe 源 URL....就像这样,假设用户 1 已登录,源 URL 应该是:

https://cpalead.com/mobile/locker/?pub=195930&gateid=985632&subid=1

我已经用一点 php 调试了这个:

echo "you are user $user";

确实显示了正确的用户。

我做错了什么?

【问题讨论】:

  • 请试试这个:cpalead.com/mobile/locker/… echo $user; ?>
  • var_dump($user) 说什么?当您询问有关错误的问题时,总是,发布错误日志。要为您的 php 代码启用错误报告,请在脚本顶部附加 error_reporting(E_ALL); ini_set('display_errors', '1');,它会返回什么?
  • 您的问题令人困惑。是 url 格式不正确还是 url 中的 userid 但在 iframe 中不可用?

标签: javascript php wordpress variables iframe


【解决方案1】:

您将其用作文本。你应该echo变量的值

<iframe src="https://cpalead.com/mobile/locker/?pub=195930&gateid=985632&subid=<?php echo $user; ?>" height="100%" frameborder="0" name="iframetarget" id="iframetarget"></iframe>

然后你可以在iframe里面使用 $_GET['subid'] 使用值

【讨论】:

  • 我正在这样做,但链接源现在是这样的:cpalead.com/mobile/locker/… echo $user; ?> php 没有被编译......该死,我正在使用带有 wordpress 的可视化作曲家
  • 您的代码在 .php 文件中吗?显示更多代码
  • 不得不为 wordpress 创建一个新的页面模板,以便更好地控制我的 iframe。它理解 echo$user 并工作了,谢谢大家!
猜你喜欢
  • 2012-06-12
  • 2020-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-29
  • 1970-01-01
  • 2017-07-11
  • 2015-09-06
相关资源
最近更新 更多