Get Logged Username
Permalink
Hey everyone,
I am wondering has the php code required to pull the logged in username changed with C5.7? I have tried the codes in the forum, the legacy documentation, have tried numerous codes off the Internet and can not get the user name. I've managed to grab admin, Array, a blank or not get any info at all. I am at a total loss here, any input would be highly appreciated.
Thanks!
I am wondering has the php code required to pull the logged in username changed with C5.7? I have tried the codes in the forum, the legacy documentation, have tried numerous codes off the Internet and can not get the user name. I've managed to grab admin, Array, a blank or not get any info at all. I am at a total loss here, any input would be highly appreciated.
Thanks!
Thanks for your reply MrKDilkington. Unfortunately that code doesn't work for me. I'm not sure why....I thought it might have been 5.7 but it must be something to do with my site configuration?
Maybe the whole story will help shed light on what's wrong. Basically I have a game on my website. In the game I am doing an Ajax call to the php file. I am wanting that php file to get the logged in user name and send it to the game with Ajax. I know that the call works, I have tested that part....but for some reason the 'default' codes to get the logged in user from Concrete just aren't working for me.
Maybe the whole story will help shed light on what's wrong. Basically I have a game on my website. In the game I am doing an Ajax call to the php file. I am wanting that php file to get the logged in user name and send it to the game with Ajax. I know that the call works, I have tested that part....but for some reason the 'default' codes to get the logged in user from Concrete just aren't working for me.
@jmfb
"In the game I am doing an Ajax call to the php file. I am wanting that php file to get the logged in user name and send it to the game with Ajax"
Is this PHP file external or in concrete5? Do you have a route registered in concrete5 that points to a class method?
"In the game I am doing an Ajax call to the php file. I am wanting that php file to get the logged in user name and send it to the game with Ajax"
Is this PHP file external or in concrete5? Do you have a route registered in concrete5 that points to a class method?
Everything is done within the Concrete5 website, the game, the php....everything. As for the route question, I would have to say...I don't know :)
How would I go about doing that?
Thanks!
Thanks!
@jmfb
I don't have personal experience with this, but here is an example from the Community Store add-on that you might find helpful.
Example: getCartSummary()
- create the route to a method
https://github.com/concrete5-community-store/community_store/blob/92...
- define your method
https://github.com/concrete5-community-store/community_store/blob/92...
- setup the AJAX to use that route
https://github.com/concrete5-community-store/community_store/blob/92...
When you create your method, you can try using the previous code for getting the username.
I don't have personal experience with this, but here is an example from the Community Store add-on that you might find helpful.
Example: getCartSummary()
- create the route to a method
https://github.com/concrete5-community-store/community_store/blob/92...
- define your method
https://github.com/concrete5-community-store/community_store/blob/92...
- setup the AJAX to use that route
https://github.com/concrete5-community-store/community_store/blob/92...
When you create your method, you can try using the previous code for getting the username.
Hopefully I can use something here. Thanks MrKDilkington!
I can't believe how difficult it is just to get the logged in user name.....I can't get any code to work.
I was also thinking it might be easier to have the player sign in with their C5 user name and password at the game level, then when the account has been confirmed by comparing to the C5 database, that user name can then be used to generate the unique save identifier I am after. If I was to do this and queried thae database would this work,or is there a modification need here?
SELECT * FROM `users` WHERE uName = 'admin' AND uPassword = md5(‘passwordhere’)
Thanks!
SELECT * FROM `users` WHERE uName = 'admin' AND uPassword = md5(‘passwordhere’)
Thanks!
where is that php file placed in your folder structure?
The php file making the call? It is in the game folder.
I've also tried an ajax call to the 'Login Dialog' plugin....got an Access Denied. I have no idea what else I can do to retrieve the logged in user name and I really need to figure this out.
I get the Access Denied when attepting to ajax call the free plugin "Login Dialog". This was my last ditch effort after trying
<?php
$u = new User();
print $u->getUserID();
?>
I've tried this and several variations of this (including the example given by MrKDilkington above) to get the logged in user....nothing has worked for me at all.
<?php
$u = new User();
print $u->getUserID();
?>
I've tried this and several variations of this (including the example given by MrKDilkington above) to get the logged in user....nothing has worked for me at all.
What I meant is you might have to show us the whole thing, preferably zipped with the proper folders so we can test locally
You can try this: