简体   繁体   English

PHP,Wordpress die(); 问题

[英]PHP, Wordpress die(); problems

Having an odd problem. 有一个奇怪的问题。
I have a plugin that I'm using that is a login register page that uses die(); 我有一个正在使用的插件,它是使用die();的登录注册页面die(); when it runs normally it just kills the page after login and redirects showing the user is now logged in but returns to same page where it logins into. 当它正常运行时,它只会在登录后杀死该页面并重定向,显示该用户现在已登录,但返回到其登录所在的页面。 What I want is to redirect to the homepage after die(); 我想要的是在die();之后重定向到主页die(); but it doesn't work. 但这不起作用。

Here is the code (Exemple 1): 这是代码(示例1):

else {
                echo json_encode(array('loggedin'=>true, 'message'=>__('Login successful, redirecting now')));
            }
            die();

The code that I thought would work is this (Exemple 2): 我认为可行的代码如下(示例2):

 else {
                echo json_encode(array('loggedin'=>true, 'message'=>__('Login successful, redirecting now')));
            }
            wp_redirect( 'https://example.com/some/page' )
            die();

However putting anything before die causes the page to just do nothing. 但是,将任何内容置于die会使页面无所事事。 It shows a gif saying it's thinking but never reloads never refreshes page never redirects. 它显示了一个gif,表示正在考虑,但是从不重新加载,从不刷新页面,从不重定向。 If I force it to reload the page it just says im logged in and returns me to the login page, but not the home page or anything I set in example 2. 如果我强迫它重新加载页面,它只会说我已登录并返回登录页面,而不是主页或我在示例2中设置的任何内容。

Any ideas? 有任何想法吗?

PS: I've tried exit(); PS:我已经尝试过exit(); with the same described results. 具有相同的描述结果。

turns out i figured it out myself. 原来我自己想通了。

            if (is_user_logged_in()) {
               echo "<script>location.href='http://www.example.com';</script>";
               die();

        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM