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.com but i installed wordpress on blog.mydomain.com

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"

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 Nov 20 '12 at 16:31
2

I solved the problem. Here's the solution.

Add this line to your wp-config.php :

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

save the file and upload. That's all.

-1

Visit Cookie settings for session across WPML subdomains using custom AJAX login I think you must add the subdomain to allowed_http_origins filter also check the request URL must be from blog.mydomain.com and request Origin and Referer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.