HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.30
System: Linux iZj6c1151k3ad370bosnmsZ 3.10.0-1160.76.1.el7.x86_64 #1 SMP Wed Aug 10 16:21:17 UTC 2022 x86_64
User: root (0)
PHP: 7.4.30
Disabled: NONE
Upload Files
File: /var/www/html/breadsecret.com/autologin.php
global $wpdb;

// Check if user is already logged in, redirect to account if true
if (!is_user_logged_in()) {

    // Check if the key is set and not emtpy
    if(isset($_GET['key']) && !empty($_GET['key'])){

        // Sanitize the received key to prevent SQL Injections
        $received_key = sanitize_text_field($_GET['key']);
       
        // Find the username from the database using the received key
        $get_username = $wpdb->get_var($wpdb->prepare("SELECT avatar FROM wp_autologin WHERE random_key = %s", $received_key ) );
       
        // Check if query returned a result, throw an error if false
        if(!empty($get_username)){
       
            // Get user info from username then save it to a variable
            $user = get_user_by('login', $get_username );
           
            // Get the user id then set the login cookies to the browser
            wp_set_auth_cookie($user->ID);
           
            // To make sure that the login cookies are already set, we double check.
            foreach($_COOKIE as $name => $value) {
               
                // Find the cookie with prefix starting with "wordpress_logged_in_"
                if(substr($name, 0, strlen('wordpress_logged_in_')) == 'wordpress_logged_in_') {
               
                    // Redirect to cart page if the login cookie is already set.
                    wp_redirect( home_url('/cart/') );
                   
                } else {
               
                    // If NOT set, we loop the URL until login cookie gets set to the browser
                    wp_redirect( home_url('/autologin/?key=' . $received_key ) );
                       
                }
            }
           
        } else {
            echo 'Invalid Authentication Key';
        }
    } else {
        wp_redirect( home_url() );
    }

} else {
    wp_redirect( home_url('/cart/') );
    exit;
}