-
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?
-
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.
-
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.
-
Is this form generated with the form generator? If yes, create a new hidden field and use this insert tag as its valueHowever, 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 …
}
-
Thanks a lot!
I used the second method and it works.