+ Post New Thread
Results 1 to 15 of 15
Scripts Thread, PHP script to display username in Coding and Web Development; I need a simple php script to display the logged on users username on our vle. Can anyone help? Thanks...
  1. #1
    tri_94's Avatar
    Join Date
    Feb 2007
    Location
    Lincolnshire
    Posts
    117
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    17

    PHP script to display username

    I need a simple php script to display the logged on users username on our vle. Can anyone help?
    Thanks

  2. #2
    Marci's Avatar
    Join Date
    Jun 2008
    Location
    Wakefield, West Yorkshire
    Posts
    888
    Thank Post
    84
    Thanked 234 Times in 193 Posts
    Rep Power
    82
    Not without knowing specifically which VLE you're using... but generally, find out the variable that holds the username, and echo it...

    eg: For Moodle1/2
    PHP Code:
    echo $USER->username
    Last edited by Marci; 28th June 2011 at 12:59 PM.

  3. #3

    vikpaw's Avatar
    Join Date
    Sep 2006
    Location
    Saudi Arabia
    Posts
    5,848
    Thank Post
    671
    Thanked 1,383 Times in 1,145 Posts
    Rep Power
    350
    I'm no PHP expert so this code might depend on your setup, but i do it like this:

    <?php
    echo $_SERVER['LOGON_USER'];
    ?>

  4. #4
    Marci's Avatar
    Join Date
    Jun 2008
    Location
    Wakefield, West Yorkshire
    Posts
    888
    Thank Post
    84
    Thanked 234 Times in 193 Posts
    Rep Power
    82
    That one should only work for VLEs running ntlm authentication via mod_ntlm or similar... like I said, it's specific to the VLE and how it's hosted as to how you can access it's variables. Without more detailed info, we're all just plucking feathers from our asses.

  5. #5
    tri_94's Avatar
    Join Date
    Feb 2007
    Location
    Lincolnshire
    Posts
    117
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    17
    Quote Originally Posted by Marci View Post
    That one should only work for VLEs running ntlm authentication via mod_ntlm or similar... like I said, it's specific to the VLE and how it's hosted as to how you can access it's variables. Without more detailed info, we're all just plucking feathers from our asses.


    hi there all i get is echo $USER->username;

    displaying in ie.

  6. #6
    Marci's Avatar
    Join Date
    Jun 2008
    Location
    Wakefield, West Yorkshire
    Posts
    888
    Thank Post
    84
    Thanked 234 Times in 193 Posts
    Rep Power
    82
    Not without knowing specifically which VLE you're using...
    like I said, it's specific to the VLE and how it's hosted as to how you can access it's variables. Without more detailed info, we're all just plucking feathers from our asses.
    Which VLE are you using?

  7. #7
    tri_94's Avatar
    Join Date
    Feb 2007
    Location
    Lincolnshire
    Posts
    117
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    17
    We are using Moodle 1.9

  8. #8
    Marci's Avatar
    Join Date
    Jun 2008
    Location
    Wakefield, West Yorkshire
    Posts
    888
    Thank Post
    84
    Thanked 234 Times in 193 Posts
    Rep Power
    82
    Moodle 1.9 should display logged in user in top right corner of every page by default.
    In which moodle file are you inserting the code?

  9. #9
    tri_94's Avatar
    Join Date
    Feb 2007
    Location
    Lincolnshire
    Posts
    117
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    17
    we are trying to get SSO working on moodle 1.9, and it seems to be failing, we are trying to test that ie is pulling the username from the machine correctly so that we can elminate that as the issuse.

  10. #10
    Marci's Avatar
    Join Date
    Jun 2008
    Location
    Wakefield, West Yorkshire
    Posts
    888
    Thank Post
    84
    Thanked 234 Times in 193 Posts
    Rep Power
    82
    In which moodle file are you inserting the code?
    As per my above post...

    but if SSO is failing, there wont' be a "logged in user" for Moodle to display, as the user hasn't logged in, cos it's failed, so it won't display anything inside Moodle.

    SSO is NTLM, so therefore vikpaw's code above should work. Put
    Code:
    <?php
    echo $_SERVER['LOGON_USER'];
    ?>
    in a file called test.php, upload it to somewhere on your website, visit it in a browser. If NTLM is picking up the user correctly it'll display the username on screen, which means it's failing because your Moodle config is incorrect. If however it DOESN'T display a name on screen, NTLM isn't working correctly and your web browser isn't able to retrieve the username from Windows.
    Last edited by Marci; 28th June 2011 at 01:47 PM.

  11. #11
    tri_94's Avatar
    Join Date
    Feb 2007
    Location
    Lincolnshire
    Posts
    117
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    17
    We were just trying to test it. with the php script

  12. #12
    Marci's Avatar
    Join Date
    Jun 2008
    Location
    Wakefield, West Yorkshire
    Posts
    888
    Thank Post
    84
    Thanked 234 Times in 193 Posts
    Rep Power
    82
    Which is what the instructions in my post above are telling you how to do:

    SSO is NTLM, so therefore vikpaw's code above should work. Put
    Code:
    <?php
    echo $_SERVER['LOGON_USER'];
    ?>
    in a file called test.php, upload it to somewhere on your website, visit it in a browser. If NTLM is picking up the user correctly it'll display the username on screen, which means it's failing because your Moodle config is incorrect. If however it DOESN'T display a name on screen, NTLM isn't working correctly and your web browser isn't able to retrieve the username from Windows.

  13. #13
    tri_94's Avatar
    Join Date
    Feb 2007
    Location
    Lincolnshire
    Posts
    117
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    17
    hi there just tried that and i get a blank page in ie

  14. #14
    tri_94's Avatar
    Join Date
    Feb 2007
    Location
    Lincolnshire
    Posts
    117
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    17
    how can i find out whats wrong ?

  15. #15
    Marci's Avatar
    Join Date
    Jun 2008
    Location
    Wakefield, West Yorkshire
    Posts
    888
    Thank Post
    84
    Thanked 234 Times in 193 Posts
    Rep Power
    82
    Your webserver isn't able to get the username from windows. Work your way thru NTLM authentication - MoodleDocs step by step following whichever section is relevant to your setup (ie: depends what ver of IIS your using, or what ver of Apache you're using).

SHARE:
+ Post New Thread

Similar Threads

  1. Display CC3 username on desktop
    By polarlemniscate in forum How do you do....it?
    Replies: 2
    Last Post: 1st May 2008, 02:27 PM
  2. Display Username Of A Remote Computer
    By FN-GM in forum Wiki Announcements
    Replies: 2
    Last Post: 28th April 2008, 01:43 PM
  3. Replies: 2
    Last Post: 26th February 2008, 08:20 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •