最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

api - wp_signon returns user but the user is not logged in because wp installed on subdomain. How to make it work?

programmeradmin2浏览0评论

I am using the WordPress API to get the user login. My code:

<?php
define('WP_USE_THEMES', false);
require('wp-blog-header.php');

$creds = array();
$creds['user_login'] = 'user';
$creds['user_password'] = 'password';
$creds['remember'] = true;
$user = wp_signon( $creds, false);
if ( is_wp_error($user) )
   echo $user->get_error_message();

$cookie = wp_set_auth_cookie($user->ID); ?>

these codes are working on my main domain www.mydomain but i installed wordpress on blog.mydomain

I think there is a cookie problem. I tested the codes above on subdomain and i got user logged in.

So how can i solve the problem?

P.s : there isnt problem with including "wp-blog-header.php"

I am using the WordPress API to get the user login. My code:

<?php
define('WP_USE_THEMES', false);
require('wp-blog-header.php');

$creds = array();
$creds['user_login'] = 'user';
$creds['user_password'] = 'password';
$creds['remember'] = true;
$user = wp_signon( $creds, false);
if ( is_wp_error($user) )
   echo $user->get_error_message();

$cookie = wp_set_auth_cookie($user->ID); ?>

these codes are working on my main domain www.mydomain but i installed wordpress on blog.mydomain

I think there is a cookie problem. I tested the codes above on subdomain and i got user logged in.

So how can i solve the problem?

P.s : there isnt problem with including "wp-blog-header.php"

Share Improve this question edited Nov 20, 2012 at 16:31 Chip Bennett 55.1k8 gold badges91 silver badges170 bronze badges asked Nov 20, 2012 at 14:55 MuratMurat 1214 bronze badges 1
  • Please do not edit titles to indicate solved status. Also, please place solutions as an answer, rather than as an edit to the question. – Chip Bennett Commented Nov 20, 2012 at 16:31
Add a comment  | 

1 Answer 1

Reset to default 2

I solved the problem. Here's the solution.

Add this line to your wp-config.php :

define('COOKIE_DOMAIN', '.yourdomain');

save the file and upload. That's all.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论