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.

$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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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