HI all,
I am trying to display user (ad displayname) welcome message on my web site but I am not sure how to achieve it. I found somthing online but that doesn't make any sence to me as I dont have nay value of $user_ID in the below code,

< ?php global $user_ID; if( $user_ID ) : ?>
< ?php if( current_user_can('level_0') ) : ?>

Welcome back < ?php global $current_user; get_currentuserinfo(); echo ($current_user->user_login); ?>. In case youve missed anything, heres what weve recently posted.

<ul>< ?php wp_get_archives('type=postbypost&limit=5'); ?></ul>
< ?php else : ?>
< ?php endif; ?>
< ?php endif; ?>

Problem is that I dont want to take any input from the user otherwise its pretty easy to do it. I am sure there would be some as there many websites that does it for you. We have an internal web site that does it. I just dont know how to..:)
It will be great if some one could help me out with it.

Regards,
SM.

To display the username and display name all you need to do is use get_currentuserinfo() :

<?php
//Declare a global to hold the user's username and display name
global $user_login, $display_name;

//Get the user's information
get_currentuserinfo();

//Then display a welcome message
echo "<strong>Welcome back {$display_name} ({$user_login})!</strong>"
?>

Use the current_user_can('level_x'); function to determine the rank of the user. Here's the different level codes:

Administrator - Level 10 (level_10)
Editor - Level 7 (level_7)
Author - Level 4 (level_4)
Contributor - Level 2 (level_2)
Subscriber - Level 0 (level_0)

Knowing this you can show certain text to authors or above only:

<?php if(current_user_can("level_4")): ?>
   <b>Hey Authors, Editors, and Admins!</b>
<?php endif; ?>

Hi,
I did tried your code but I get the Fetal error: call to undefined function get_currentuserinfo();
Do you know what plugin or class I would have to install or any changes that I need to make to php.ini to get it working. I am using php 5.1.6

Use session to get username and echo

Thanks ayesha I wish it would be that easy for me. :)
Problem that I am dealing is little complex. What I am expecting is that get_currentuserinfo() would get me the ad display name and from there I can map to the cname of the user and verify against the ad group that belongs.
Actually its a sub step of the actual problem that I am dealing with. Here is what I am actually trying to do,
In case I take the username/pass and bind against ad using ldap, we have got to different windows accounts.One is structured like firstname.ln@company.com other is regional account lets say uk account, we can login to windows with both of them with same password but I cant bind the LDAP connection using uk account. The common name (cn) in active directory is based on uk account name.

What I have asked above would get me the cname or display name of the user and then I verify the user group from there.

Ya because I found that this function needs pluggable.php class for which i had to install wordpress. But its a joke you create a db in there to make it work which I could have done myself.

Wordpress is not a solution I am looking for coz you have to add user records to db which I didnt wanted at the first place.
I am using LDAP to communicate to AD

Now the question is was I not suppose to use wordpress?
I get undefined function, fetal error otherwise
Please let me know if it would work otherwise (without wordpress) and how to make it work.

You cannot install wordpress just for a function. The functions that come with wordpress are meant to be used within wordpress. Why not create your own user system. It's must easier than trying to piece-meal one together from pre-written scripts.

I know what you are saying but ur comments are not helping mate. Misguided me first, I wasted whole day working on wordpress as I had never used it before. Ofcourse I can make my own user system much quicker but I dont want to go that way.

Do you know anything about ldap?
If yes then my question is that I am using the below code to intract with ad and I can retrieve the attributes like displayname, cn, sn but for some reason I cant get values for 'userPrincipalName, distinguishedName, sAMAccountNAme' etc..
Please let me know if you can think of any reason. Here is the code,

<?php 
    $username =  $_POST['username']; 
    $password =  $_POST['password']; 
    $dn = "ou=Users,ou=Accounts,OU=GB,dc=eur,dc=msd,dc=world,dc=company 
    $ad = ldap_connect("ldap://ldap_server") 
          or die("Couldn't connect to AD!"); 
        $attribute = array("userPrincipalName" , "cn","sAMAccountName", "distinguishedName"); 

    ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3); 
    ldap_set_option($ad, LDAP_OPT_REFERRALS, 0) 
or die ("Could not set option referrals"); 
$bd = ldap_bind($ad,$username,$password) 
          or die("Couldn't bind to AD!"); 
$entries = ""; 
$filter_array = array('(cn=user1)', '(cn=user2)');   
for($j= 0; $j<count($filter_array); $j++)  
 { 
    $result = ldap_search($ad, $dn,$filter_array[$j], $attribute); 

    $entries = ldap_get_entries($ad, $result); 
for ($i=0; $i<$entries["count"]; $i++) 
    { echo $entries[$i]["displayname"] // can change the attributes here to display 
             [0]."(".$entries[$i]["l"][0].")<br />"; 
    }   
} 
ldap_unbind($ad); 
?>

Does the user information store in your database any where?

I wish that would be the case. Problem is we dont want to do it that way for few reasons...

you are even not taking username from users? right? whats in your mind, how you can display username if you dont have it any where?

I wish that would be the case. Problem is that we dont to go that way, otherwise I would have done it ages ago.
Can you think any other way.

sorry I couldn't see ur last message.
Now I am taking the windows credentials coz I couldn't found any solution.
what I am trying to do is simple. When user login with the windows credentials, I make a bind to ad using LDAP and retrieve userinformation from there I can do whatever I like.
Problemis that I can search attributes like displayname, cn etc but for some reason I cant get to see the one I am willing to like userPrincipalName...
Thing is that userPrincipalName is same as your login name and if I will be able to find that then I can authenticate user against their groups based on userPrincipalName filter.
hope you understand what I am trying to say

I think you want a new programming trick in which we can know the person name without even knowing his/her name. wowww... Isn't it magic??????? You even dont want to let user tell his/her name in any way but your want to shock him by showing his/her name. Good haan.... Keep it upppp

Here is how you do it.... took me time but ya it is possible bzzBee, just have to think a bit to aim to be able to achieve, no magic trust me :)

There are two magic php variables which would get you username of the person logged into windows.
$_SERVER , $_SERVER

Pick them up from client side, create a dummy/web account in ad, use windows authentication for that account, use the cn (common name) or userpricipalname attribute , check the user group membership and thats it job done.