Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Une instance de la classe User représente un utilisateur. Ces instances sont uniques et comparables. Si deux instances sont égales, elles représentent le même utilisateur.
L'application peut accéder à l'instance "User" de l'utilisateur actuel en appelant la fonction UserService::getCurrentUser().
Vous pouvez utiliser la fonction UserService::getCurrentUser() quelle que soit l'option d'authentification employée par votre application.
Une instance User peut également être créée à partir d'une adresse e-mail :
$user = new User('Albert.Johnson@example.com');
Si la fonction User::__construct() est appelée avec une adresse e-mail qui ne correspond pas à un compte Google valide, l'objet sera créé, mais il ne correspondra pas à un compte Google réel. Cela se produit même si un utilisateur crée un compte Google avec l'adresse e-mail fournie après le stockage de l'objet. Une valeur User associée à une adresse e-mail ne représentant pas un compte Google au moment de sa création ne correspondra jamais à une valeur User représentant un véritable utilisateur.
L'objet User d'un utilisateur valide peut fournir une valeur d'identifiant unique à l'utilisateur, qui reste identique même si l'adresse e-mail change. La méthode getUserId() renvoie cet identifiant, à savoir une valeur string.
Quelle que soit la méthode d'authentification utilisée par votre application, l'objet User présente toujours le même format.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[[["\u003cp\u003eThe \u003ccode\u003eUser\u003c/code\u003e class represents a unique user, and two equal instances signify the same user.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eUserService::getCurrentUser()\u003c/code\u003e retrieves the \u003ccode\u003eUser\u003c/code\u003e instance for the current user, regardless of the authentication method.\u003c/p\u003e\n"],["\u003cp\u003eA \u003ccode\u003eUser\u003c/code\u003e instance can be created from an email address, but it may not correspond to a valid Google account.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egetUserId()\u003c/code\u003e method of a \u003ccode\u003eUser\u003c/code\u003e object provides a unique ID that remains consistent even if the user's email changes.\u003c/p\u003e\n"],["\u003cp\u003eThis API is only for first-generation runtimes, and a migration guide is available for updates to PHP 7/8 runtimes.\u003c/p\u003e\n"]]],[],null,["# User Objects\n\nAn instance of the [User](/appengine/docs/legacy/standard/php/refdocs/classes/google.appengine.api.users.User) class represents a user. User instances are unique and comparable. If two instances are equal, then they represent the same user.\n| This page describes how to use the legacy bundled services and APIs. This API can only run in first-generation runtimes in the App Engine standard environment. If you are updating to the App Engine PHP 7/8 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/php-differences) to learn about your migration options for legacy bundled services.\n\nThe application can access the User instance for the current user by calling the [`UserService::getCurrentUser()`](/appengine/docs/legacy/standard/php/refdocs/classes/google.appengine.api.users.UserService#method_getCurrentUser) function. \n\n use google\\appengine\\api\\users\\UserService;\n\n $user = UserService::getCurrentUser();\n\n if (isset($user)) {\n return sprintf('Welcome, %s! (\u003ca href=\"%s\"\u003esign out\u003c/a\u003e)',\n $user-\u003egetNickname(),\n UserService::createLogoutUrl('/'));\n } else {\n return sprintf('\u003ca href=\"%s\"\u003eSign in or register\u003c/a\u003e',\n UserService::createLoginUrl('/'));\n }\n\nYou can use the `UserService::getCurrentUser()` function no matter which authentication option your app uses.\n\nA User instance can be also constructed from an email address: \n\n $user = new User('Albert.Johnson@example.com');\n\nIf the [`User::__construct()`](/appengine/docs/legacy/standard/php/refdocs/classes/google.appengine.api.users.User#method___construct) is called with an email address that does not correspond with a valid Google account, the object will be created but it will not correspond with a real Google account. This will be the case even if someone creates a Google account with the given email address after the object is stored. A User value with an email address that does not represent a Google account at the time it is created will never match a User value that represents a real user.\n\nThe User object for a valid user can provide a unique ID value for the user that stays the same even if the user changes her email address. The [`getUserId()`](/appengine/docs/legacy/standard/php/refdocs/classes/google.appengine.api.users.User#method_getUserId) method returns this ID, a `string` value.\n\nThe User object has the same form no matter which method of authentication your app uses."]]