WordPress wp-blog-header.php causing database authentication issues

I’m having trouble with my custom authentication system after adding WordPress integration. My site has a basic user login where people type their username and password, then click submit to send the data to a PHP script that validates against the database. Everything works perfectly on its own.

The problem starts when I include the WordPress header file to show recent blog posts from my WordPress installation in the same directory. As soon as I add include('wordpress/wp-blog-header.php'), my login stops working and throws database connection errors saying the database credentials are invalid.

Here’s my authentication form code:

if(!isset($_SESSION['user_status']) || $_SESSION['user_status'] == NULL) {
    $loginForm = "<h1>User Authentication <small style='color:#E54FBF'>please enter login details</small></h1>
        <p>
            <label for='userid'>User ID: </label>
            <input type='text' name='userid' required />
        </p>
        <p>
            <label for='userpass'>Password: </label>
            <input type='password' name='userpass' required />
        </p>
        <p>
            <input type='submit' id='loginBtn' value='Sign In' name='loginBtn' />
        </p>";
}

And the submission handler:

if($_POST && !empty($_POST['userid']) && !empty($_POST['userpass'])) {
    $result = $userAuth->check_credentials($_POST['userid'], $_POST['userpass']);
}

The strange part is that the error mentions wrong database credentials for the connection itself, not the user input. I double checked my database settings and they’re correct. It seems like WordPress is somehow interfering with my database connection. Has anyone experienced similar issues when mixing custom PHP with WordPress includes?

WordPress wp-blog-header.php loads the entire WordPress core, including its database connection handling through wp-config.php. WordPress is probably overriding your existing database connection or messing with global variables your custom auth system needs. I hit this exact problem a few years ago when integrating WordPress with an existing member portal. The fix was establishing my custom database connection after including the WordPress header, not before. Also check if WordPress is using the same database connection variable names as your custom system. Another approach that worked for me was using WordPress’s $wpdb object for your auth queries instead of maintaining separate connections, though you’ll need to restructure some code.

Had this exact nightmare 6 months ago. WordPress messes with PHP’s error reporting and database connection defaults when wp-blog-header.php loads, which breaks existing connections that need specific error handling or connection parameters. Your custom auth system probably uses different database settings than WordPress expects. What saved me: store your original database connection object in a separate variable before including WordPress, then restore it after. Also check if your wp-config.php has charset or collation settings that differ from your custom system. Timing matters too - WordPress assumes it owns the database layer once it’s loaded.

wordpress is probably hijacking your db connection vars. try wrapping your auth code in a func or namespace to keep it separate from wp globals. plus, use wp-load.php instead of wp-blog-header.php, its outdated. had the same headaches when wp messed with my $db_connection vars.