The MU forums have moved to WordPress.org

authenticate the user directly from index page and redirect to dashboard (8 posts)

  1. fritzdsouza
    Member
    Posted 15 years ago #

    Hi
    I have installed wordpress 1.5.1 and wanted to try this
    the user who comes to the mu site should be redirected to the dashboard am trying to integrate mu with another php mysql system for a project but right now need to figure out from index page how to redirect users to their dashboard directly something like logging the admin user in from the index page itself for right now will be very helpful for me

  2. fritzdsouza
    Member
    Posted 15 years ago #

    I have tried hard coding the username and passwd in user.php wp_sigon function and calling this from the wp-blog-header.php but that does not seem to work :(

    am I doing something wrong??

  3. dsader
    Member
    Posted 15 years ago #

    global $user_level;
    if ( !isset($user_level) ) {
    nocache_headers();
    header("HTTP/1.1 302 Moved Temporarily");
    header('Location: ' . get_settings('siteurl') . '/wp-login.php?redirect_to=' . urlencode('wp-admin'));
    header("Status: 302 Moved Temporarily");
    exit();
    }
    }

  4. fritzdsouza
    Member
    Posted 15 years ago #

    hi dsader

    tried this code on the index page but does not work it takes me to the sign up from
    i tried this code on the index page

    what i tried is modifying blogheader file but the problem is that i now get to my dashboard but i cant see any other page outside the wp-admin folder as any other page takes me back to the wp-admin folder even the preview of the posts that i am writing

  5. cafespain
    Member
    Posted 15 years ago #

    fritzdsouza: Do you want all users sent to the admin panel or only registered or logged in users?

  6. fritzdsouza
    Member
    Posted 15 years ago #

    hi cafespain

    right now since i am just trying with one user tht is admin just need that user to go to the dashboard directly once that user lands on the indexpage he gets to the dashboard without login in

    am just studying the auth part so that it later becomes easy for me to integrate with some other php based sites

  7. fritzdsouza
    Member
    Posted 15 years ago #


    <?php

    if (! isset($wp_did_header)):
    if ( !file_exists( dirname(__FILE__) . '/wp-config.php') ) {
    if (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false) $path = '';
    else $path = 'wp-admin/';

    include( "index-install.php" ); // install WPMU!
    die();
    }

    $wp_did_header = true;

    require_once( dirname(__FILE__) . '/wp-config.php');
    require_once( dirname(__FILE__) . '/wp-includes/user.php');
    $user = wp_signon();

    wp();

    $redirect_to = get_option('siteurl') . '/wp-admin/';
    wp_safe_redirect($redirect_to);

    require_once(ABSPATH . WPINC . '/template-loader.php');

    endif;

    ?>

    This is working for me but the problem is i get redirected to the wpadmin section from every page not just the index page

  8. dsader
    Member
    Posted 15 years ago #

    Sorry fritzdsouza,

    The header redirect above will only work from within header.php of your template. It will redirect non-users to the login form, then direct the logged-in user to the dashboard. Once logged in, it will do nothing to the user.

    You could add another redirect

    global $user_level;
    if ( isset($user_level) ) {
    nocache_headers();
    header("HTTP/1.1 302 Moved Temporarily");
    header('Location: ' . get_settings('siteurl') . '/wp-login.php?redirect_to=' . urlencode('wp-admin'));
    header("Status: 302 Moved Temporarily");
    exit();
    }
    and logged in users will also be redirected(removed the !).

    Use both and no one will see the front page, ever.

About this Topic

  • Started 15 years ago by fritzdsouza
  • Latest reply from dsader