WordPress.org

Forums

Automatic logon from sub-page (1 post)

  1. PAdrichem
    Member
    Posted 6 years ago #

    Hi there i'm trying to get my users to automaticly logon.

    We've got an Active Directory server, and an ASP written page that redirects it to the wordpress authentication page, also written by us, with a couple of security hashes etc etc, to end up with a username,

    thats the username thats also used in wordpress, but we don't have a password, so using only the username, i'm trying to get this user to log on.

    I've written the following code:

    require_once('wp-config.php');
    define('DB_NAME', ''); // The name of the database
    define('DB_USER', ''); // Your MySQL username
    define('DB_PASSWORD', ''); // ...and password
    define('DB_HOST', ''); // 99% chance you won't need to change this value
    define('SITECOOKIEPATH', '/' );
    define('COOKIEPATH', '/' );
    define('PLUGINS_COOKIE_PATH', '/' );
    define('ADMIN_COOKIE_PATH', '/' );
    define('COOKIE_DOMAIN', '.domain.com');
    define('COOKIEHASH', md5('siteurl'));
    define('AUTH_COOKIE', 'wordpress_' . COOKIEHASH);
    define('LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH);

    require_once('wp-includes/wp-db.php');
    global $wpdb;
    $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
    require_once('wp-includes/plugin.php');
    require_once('wp-includes/cache.php');
    require_once('wp-includes/formatting.php');
    require_once('wp-includes/pluggable.php');
    require_once('wp-includes/functions.php');
    require_once('wp-includes/user.php');
    require_once('wp-includes/capabilities.php');
    wp_cache_init();
    $user = get_userdatabylogin($sUserName);
    $user_id = $user->ID;
    wp_set_current_user($user_id, $sUserName);
    wp_set_auth_cookie($user_id);
    setcookie("wordpress_text_cookie", "WP Cookie check", time() + 3600, COOKIEPATH, COOKIE_DOMAIN);

    ofcourse the defines are set with the correct values.

    now this results into a cookie, on wordpress, but the user is not logged on.

    The cookie i'm getting is:

    array(4) {
    ["LOGGED_IN_COOKIE"]=> string(44) "|1225284289|ee0c5758b06c3d7cc4e70dbb424e578b"
    ["wordpress_3e64eb02a8d3e69400c9a472c722ec85"]=> string(54) "p.adrichem|1225286549|a54e811c557cc1be706dc93b7e4569c1"
    ["wordpress_logged_in_3e64eb02a8d3e69400c9a472c722ec85"]=> string(54) "p.adrichem|1225286549|a5663fe9df161bab4fc8c74425327dd4"
    ["wordpress_test_cookie"]=> string(15) "WP Cookie check"
    }

    while it should've been:

    array(2) {
    ["wordpress_test_cookie"]=> string(15) "WP Cookie check"
    ["wordpress_logged_in_3e64eb02a8d3e69400c9a472c722ec85"]=> string(54) "p.adrichem|1225287169|3ec9527060d1f5a23f0653590458deee" }

    does anyone know what i'm doing wrong?

Topic Closed

This topic has been closed to new replies.

About this Topic