WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Using wordpress sessions in other php pages : login (3 posts)

  1. scotnery
    Member
    Posted 5 years ago #

    I am using the wordpress sessions in other non-wordpress pages to tell me if the user is logged in and their username and password. I think I'm doing it wrong. Could someone please guide me to the right way to do this?

    Here's the code I'm currently using in each non-wp php file:

    if($page_section != "news"){
    	$blog_location = $_SERVER['DOCUMENT_ROOT'] . "/news";
    	if (! isset($wp_did_header)):
    	if ( !file_exists( $blog_location . '/wp-config.php') ) {
    		if (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false) $path = '';
    		else $path = 'wp-admin/';
    
    		require_once( $blog_location . '/wp-includes/classes.php');
    		require_once( $blog_location . '/wp-includes/functions.php');
    		require_once( $blog_location . '/wp-includes/plugin.php');
    		wp_die("There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://codex.wordpress.org/Editing_wp-config.php'>We got it</a>. You can create a <code>wp-config.php</code> file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file.</p><p><a href='{$path}setup-config.php' class='button'>Create a Configuration File</a>", "WordPress &rsaquo; Error");
    	}
    
    	$wp_did_header = true;
    
    	require_once( $blog_location . '/wp-config.php');
    
    	wp();
    
    	endif;
    
    }
  2. stvwlf
    Member
    Posted 5 years ago #

    Hi

    This article explains a way to access WP content outside of WP. It allows access to any WP function, so it should be relevant to your need even though the article is about displaying WP content.
    http://www.corvidworks.com/articles/wordpress-content-on-other-pages

  3. scotnery
    Member
    Posted 5 years ago #

    Thank you.

Topic Closed

This topic has been closed to new replies.

About this Topic