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

admin2025-04-19  1

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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745014483a280007.html

最新回复(0)