如何在自己的项目中使用wp_set_current_user?

I have tried using wp_set_current_user function in my project to automatically log in to WordPress from my project. The code is shown below:

$q = mysql_query("select * from user where email='$email' and password='$password'");

if (mysql_num_rows($q) == 1) {
   require_once 'wordpress/wp-includes/pluggable.php';    
   $user_id = 5;

   wp_set_current_user( $user_id, "bookmark" );
   wp_set_auth_cookie( $user_id );
   do_action( 'wp_login', "bookmark" );
}

I have followed instructions from official docs.

The code above doesn't work and I'm not sure that I wrote the code properly.

You can use wp_singon function:

$creds[‘user_login’] = $first_name;

// ACCOUNT PASSWORD TO USE

$creds[‘user_password’] = $password;
$creds[‘remember’] = true;
$autologin_user = wp_signon($creds, false);

if (!is_wp_error($autologin_user))
{
$home_url = get_home_url() . ” / ? reg = true”;
wp_redirect($home_url);
}

here is official link: LINK

Make sure you have a wordpress user with id 5 and username "bookmark" . then try this code.

 $user_id =5;
 $current_user = new WP_User( $user_id, "bookmark" );
 setup_userdata( $current_user->ID );