Get current user data from external PHP page

You can…

Load the file into the file where you want to display the ‘hey username’ message:

<?php include(TEMPLATEPATH .'/check-user-hello.php'); ?>

.
Then in that file “check-user-hello.php”
You need to put this code

<?php
if ( is_user_logged_in() ) {
global $current_user;
get_currentuserinfo();
echo 'Hey ' . $current_user->display_name;
} else {
echo '<a href="'. get_bloginfo('url') .'/wp-admin" class="loginlinktop">Login</a>';
}
?>

.
Hope This Helps 🙂

TO learn more about this subject:

.
FIX 3

To the best of my knowledge you need to grab wp-blog-header.php in order to run WordPress functions outside of the loop.. so.. try this.

<?php

require('../../../wp-blog-header.php');

if ( is_user_logged_in() ) {
global $current_user;
get_currentuserinfo();
echo 'Hey ' . $current_user->display_name;
} else {
echo '<a href="'. get_bloginfo('url') .'/wp-admin" class="loginlinktop">Login</a>';
}
?>

.
Please NOTE:
THE “wp header blog” PATH i have created in this code is assuming your file is in your template directory.. if its not you should change the path of require so it would load the file correctly.