wordpress wp_signon 功能不起作用 [英] wordpress wp_signon function not working

查看:20
本文介绍了wordpress wp_signon 功能不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 wp_signon() 函数登录用户.我正在这样做

I am using wp_signon() function to login the user. I am doing this like

$creds = array();

$creds['user_login'] = $username;

$creds['user_password'] = $password;

$creds['remember'] = true;

$user = wp_signon( $creds, false );

我想在登录后将用户发送到主页.

i want to send user to home page after login.

但我面临以下错误:

警告:无法修改标头信息 - 标头已发送(输出开始于 E:\xampp\htdocs\wpmoodle\wp-content\themes\twentyten\header.php:12)在 E:\xampp\htdocs\wpmoodle\wp-includes\pluggable.php 第 690 行.

Warning: Cannot modify header information - headers already sent by (output started at E:\xampp\htdocs\wpmoodle\wp-content\themes\twentyten\header.php:12) in E:\xampp\htdocs\wpmoodle\wp-includes\pluggable.php on line 690.

提前致谢.

推荐答案

wp_signon() 需要在您将任何实际页面发送到浏览器之前运行.

wp_signon() needs to run before you've sent any of your actual page to the browser.

这是因为 wp_signon() 所做的部分工作是设置您的身份验证 cookie.它通过输出一个 "Set-Cookie: ..." 标头来实现这一点——如果你查看 pluggable.php 的第 690 行,你的错误来自哪里,你会看到那行设置一个饼干.

This is because part of what wp_signon() does is to set your authentication cookies. It does this by outputting a "Set-Cookie: ..." header -- if you look at line 690 of pluggable.php, where your error comes from, you'll see that that line sets a cookie.

所以,因为 wp_signon() 输出 headers,你不能已经发送任何 content -- 因为必须总是输出 headers在内容之前.

So, because wp_signon() outputs headers, you can't already have sent any content -- because headers must always be output before content.

但是,该错误表明您已经发送了一些输出——在 header.php 的第 12 行,大概是标准 WordPress 主题的一些第一个 HTML.

However, the error indicates that you've already sent some output -- on line 12 of header.php, presumably some of the first HTML of the standard WordPress theme.

这基本上表明您需要将 wp_signon() 调用移动到 WordPress 处理中较早的某个位置,因此它有机会在发送任何页面内容之前输出其标题.

This basically indicates that you need to move your wp_signon() call to somewhere earlier in the WordPress processing, so it has a chance to output its headers before any page content is sent.

这篇关于wordpress wp_signon 功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆