Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

My friend has a code that will allow users to receive a special key to gain access into into the closed/open beta event for any game they select. When a person is logged in, they can click on a link which will show them a key. If a person is logged logged in, the event page will tell them to login. What my friend needs is a way to get the person's username from the wordpress login cookie once the person has logged in. We found out that the wordpress cookie name is unique to each user that logs in (in other words it has a string of random letters and numbers in the cookie name). Any ideas?

The piece of code we have on our page that we are using is this:

$username = $_COOKIE["nameofcookiehere"]

We need the $username variable so that every key that is given will be assigned to the username that is logged in based on the cookie and the key will be marked as "1" or "taken" in the database and the key will be assigned to that user in the database.

share|improve this question
2  
does get_currentuserinfo not do it for you? –  m0r7if3r Jan 13 '12 at 16:15

1 Answer 1

get_currentuserinfo();
$username = $current_user->user_login

That should work to get the current user's username. You can read more about get_currentuserinfo(); here in the codex. It pulls all the base info about a user - username, display name, email, first/last name, and user ID.

This will be handy since you can verify the user based on username, then assign the key in the DB according to UID.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.