Results 1 to 5 of 5

Thread: Get FrontEnd username

  1. #1
    User tetrijeb's Avatar
    Join Date
    04-19-12.
    Location
    Bosnia&Herzegovina
    Posts
    98

    Default Get FrontEnd username

    I have one database where frontend users can import csv files when they are logged in, using/calling prepared php script.

    I made a log table where I want to have information about every import (what file, username, ip, time).

    How I can get FE username of member who made the import? Is there some session variable that contain that data?
    Last edited by tetrijeb; 01/22/2016 at 10:20.

  2. #2
    User Spooky's Avatar
    Join Date
    01-03-13.
    Posts
    331

    Default

    If you are using the Framework of Contao then you can use:
    PHP Code:
    \FrontendUser::getInstance()->username 
    Maybe you need to execute
    PHP Code:
    \FrontendUser::getInstance()->authenticate() 
    first.

  3. #3
    User tetrijeb's Avatar
    Join Date
    04-19-12.
    Location
    Bosnia&Herzegovina
    Posts
    98

    Default

    From Contao page I am calling php script in external file with the form:

    Code:
    <form enctype='multipart/form-data' action='./import/iMatches.php' method='POST'>
    <input size='50' type='file' name='filename'>
    
    <input type='submit' name='Matches' value='Import Data'></form>
    so I don't know how to pass it to the script.

  4. #4
    User Spooky's Avatar
    Join Date
    01-03-13.
    Posts
    331

    Default

    Is this form generated with the form generator? If yes, create a new hidden field and use this insert tag as its value
    Code:
    {{user::username}}
    However, this data could be altered by someone. If you want to find out the username in your script (import/iMatches.php), then you need to add the following to the top of your script:
    PHP Code:
    // Initialize the system
    define('TL_MODE''FE');
    require 
    __DIR__ '/system/initialize.php'
    And then use
    PHP Code:
    if( \Contao\FrontendUser::getInstance()->authenticate() )
    {
        
    … \Contao\FrontendUser::getInstance()->username …

    Last edited by Spooky; 01/25/2016 at 13:19.

  5. #5
    User tetrijeb's Avatar
    Join Date
    04-19-12.
    Location
    Bosnia&Herzegovina
    Posts
    98

    Default

    Thanks a lot!

    I used the second method and it works.

Bookmarks

Posting Permissions

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