admin管理员组文章数量:1122832
On my localhost environment the following code works perfect
$creds['user_login'] = $user_login;
$creds['user_password'] = $user_password;
$user = wp_signon( $creds, true );
if(!is_wp_error($user)) {
wp_redirect('/home');
exit;
}
But on the server it doesn't work anymore. The user is never logged in. The website is hosted on a https subdomain on an external server.
I tried setting a cookie domain in my wp-config:
define('COOKIE_DOMAIN', '.domain');
And also with the subdomain included:
define('COOKIE_DOMAIN', 'sub.domain');
Neither worked for me.
The server runs on PHP 7.1 with Varnish. Swift Performance is used for caching.
On my localhost environment the following code works perfect
$creds['user_login'] = $user_login;
$creds['user_password'] = $user_password;
$user = wp_signon( $creds, true );
if(!is_wp_error($user)) {
wp_redirect('/home');
exit;
}
But on the server it doesn't work anymore. The user is never logged in. The website is hosted on a https subdomain on an external server.
I tried setting a cookie domain in my wp-config:
define('COOKIE_DOMAIN', '.domain.com');
And also with the subdomain included:
define('COOKIE_DOMAIN', 'sub.domain.com');
Neither worked for me.
The server runs on PHP 7.1 with Varnish. Swift Performance is used for caching.
Share Improve this question edited Jan 7, 2020 at 10:21 andy asked Jan 7, 2020 at 8:32 andyandy 1012 bronze badges 2- Can you use your browser's debug tools to look for the 'Set-Cookie' response header you're getting on login, and work out why that's wrong? – Rup Commented Jan 7, 2020 at 9:53
- There are no cookies at all in the response headers on the server. In the localhost environment I see some session cookies being set.... Do you might know if this is a server problem? – andy Commented Jan 7, 2020 at 10:19
2 Answers
Reset to default 0You need to set the auth cookie after wp_signon. Add this code and try and let me know the result.
$user = wp_signon( $creds, false );
$userID = $user->ID;
wp_set_current_user( $userID, $creds['user_login'] );
wp_set_auth_cookie( $userID, true, false );
do_action( 'wp_login',$creds['user_login'] );
Varnish was the problem.
Varnish removes cookies from the response. That's why it didn't work in our case!
本文标签: phpwpsignon works localnot on https
版权声明:本文标题:php - wp_signon works local, not on https 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736292228a1928888.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论