【问题标题】:header location not redirecting WORDPRESS标头位置不重定向 WORDPRESS
【发布时间】:2016-12-20 21:58:32
【问题描述】:

我正在使用 word-press,并在网站正文中嵌入了以下代码,希望它将用户重定向到相关页面。

$current_user = wp_get_current_user();
$e=$current_user->user_email;

$result = mysql_query("SELECT users.user_email
FROM users
WHERE users.user_email='$e'");

$numResult = mysql_num_rows($result);
if ($numResult > 0) {
header( "Location: ../Confirm" );
} else {
header( "Location: ../Insert" );
}

很遗憾,没有发生重定向...有什么想法吗?

【问题讨论】:

  • 停止输出缓冲?
  • 删除了它,但仍然没有成功
  • 尝试使用小写 L?还有 header('Location: ../Confirm');退出();
  • 尝试在标题调用后添加exit() - 请参阅here

标签: php wordpress redirect header http-redirect


【解决方案1】:

WordPress有自己的重定向函数:wp_redirect()

只要确保您的代码在其他任何事情之前执行即可。一个好地方是主题内的 header.php 文件,在标签之前。

https://developer.wordpress.org/reference/functions/wp_redirect/

【讨论】:

    猜你喜欢
    • 2014-01-10
    • 1970-01-01
    • 1970-01-01
    • 2015-02-04
    • 2019-05-22
    • 1970-01-01
    • 1970-01-01
    • 2017-06-21
    • 2022-01-17
    相关资源
    最近更新 更多