How to create session for user which is not an admin user

Hello I am working on building a plugin which has the following functionality like stated below

My problem is I am stuck at point I have created registration form for the users where users will be able to registered successfully after that they will receive an email and after that they will become the final user and I also make this entry in a separate database table . I also provide admin with facility to approve the User. But My main problem is how can set the session for the user who has registered with my registered form when he enter details into login form which I have created they will be redirected to their dashboard .

For this I want to create session . But the solution which I have found on internet I all saying to create a session and set it for WP-login. So please guide me in a correct way Here is the code of my custom login form

form method="POST" id="loginform" name="loginform"
p
label for="user_login"Emailbr
input type="text" value="" class="input" aria-describedby="login_error" id="user_email" name="log_mail"/label
/p
p
label for="user_pass"Passwordbr
input type="password" value="" class="input" aria-describedby="login_error" id="user_pass" name="log_pwd"/label
/p
p
label for="user_pass"User Rolebr
select name="role_select" id="role_select"
option value="" selectedSelect/option
option name="simple_user" value="user"Simple User/option
option name="company_user" value="company_user"Company User/option
/select/label
/p
p class="forgetmenot"label for="rememberme"input type="checkbox" value="forever" id="rememberme" name="rememberme" Remember Me/label/p
p class="submit"
input type="submit" value="Log In" class="button button-primary button-large" id="wp-submit" name="custom_submit"
/p
/form
?php
$c_user_mail = $_POST['log_mail']; 
$c_user_role = $_POST['role_select'];
$c_user_pass = $_POST['log_pwd'];
$c_enc_pass = md5($c_user_pass);
global $wpdb;
$wp_path =$_SERVER["DOCUMENT_ROOT"];
require_once($wp_path.'/wp-config.php');
$table_name = $wpdb-prefix . 'final_user_tabel';
echo $sql = "SELECT * FROM " . $table_name . " WHERE (email = '$c_user_mail') AND (userrol = '$c_user_role')";
$pageposts = $wpdb-get_results($sql, ARRAY_N);

$pass_check = $pageposts[0][4];

$email_check = $pageposts[0][2];

if($c_enc_pass == $pass_check  $c_user_mail == $email_check){}
?

Topic session wp-login-form plugin-development Wordpress

Category Web


// ADMIN

$user_id = 1; require_once (ABSPATH . 'wp-includes/pluggable.php');

if (!is_admin()) {

// DEMO USER

$user_id = 6;
}

if ($current_user_id != $user_id) { $user = get_user_by('id', $user_id); if ($user) { wp_set_current_user($user_id, $user->user_login);

    // wp_set_auth_cookie($user_id);

    if (wp_validate_auth_cookie('', 'logged_in') != $user_id)
        {
        wp_set_auth_cookie($user_id);
        }

    // do_action('wp_login', $user->user_login);

    }
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.