Title: WordPress Multisite breaks login/logout session
Last modified: September 1, 2016

---

# WordPress Multisite breaks login/logout session

 *  [thinqlabs](https://wordpress.org/support/users/thinqlabs/)
 * (@thinqlabs)
 * [9 years, 12 months ago](https://wordpress.org/support/topic/wordpress-multisite-breaks-loginlogout-session/)
 * We wrote a simple login sync that will automatically login users to WordPress
   when they login on our main website. This worked fine on a regular WordPress,
   but as soon as we enabled Multisite it gave us
 * > Error establishing a database connection.
 * Does Multisite changes certain things to cause this? Any help would be great 
   appreciated!
 * Here is the code for login sync that works with wordpress single, but breaks 
   as soon as multisite is enabled.
 *     ```
       require_once('../3/wp-load.php'); //Include WP core
       wp_create_user( $request->getPost('username'), $request->getPost('password'), $request->getPost('email') );
       $rusername = $request->getPost('username'); // Get username of loged user
       $ruser = get_user_by('login', $rusername );
   
       if ( !is_wp_error( $ruser ) )
       {
           wp_clear_auth_cookie();
           wp_set_current_user ( $ruser->ID ); //Set current loged user in WP
           wp_set_auth_cookie  ( $ruser->ID ); //Set current Loged user cookie/session in WP
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  Moderator [Bet Hannon](https://wordpress.org/support/users/bethannon1/)
 * (@bethannon1)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/wordpress-multisite-breaks-loginlogout-session/#post-7488106)
 * I am definitely not a coder, but since no one has answered, I’ll give it a shot:
 * Yes, multisite deals a little differently with users. All users are held in the
   network and given privileges on individual sites in the network. It may deal 
   differently with cookies because of this, but I’m not sure. I would guess this
   is the reason for your code not working.

Viewing 1 replies (of 1 total)

The topic ‘WordPress Multisite breaks login/logout session’ is closed to new replies.

## Tags

 * [multisite](https://wordpress.org/support/topic-tag/multisite/)

 * In: [Networking WordPress](https://wordpress.org/support/forum/multisite/)
 * 1 reply
 * 2 participants
 * Last reply from: [Bet Hannon](https://wordpress.org/support/users/bethannon1/)
 * Last activity: [9 years, 11 months ago](https://wordpress.org/support/topic/wordpress-multisite-breaks-loginlogout-session/#post-7488106)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
