[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eThe Users API allows developers to create URLs for user sign-in and sign-out actions, redirecting them back to the application afterward.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eUserService::createLoginUrl()\u003c/code\u003e and \u003ccode\u003eUserService::createLogoutUrl()\u003c/code\u003e functions generate the URLs for signing in and out, respectively, while requiring a destination URL for redirection.\u003c/p\u003e\n"],["\u003cp\u003eThe development web server simulates Google Accounts with its sign-in/sign-out mechanisms, prompting for an email address when signing in locally.\u003c/p\u003e\n"],["\u003cp\u003eAccess to specific parts of an application can be restricted to signed-in users using the \u003ccode\u003elogin: required\u003c/code\u003e configuration element for URL handlers.\u003c/p\u003e\n"],["\u003cp\u003eThis API is specific to first-generation runtimes in the App Engine standard environment and has different options in later versions.\u003c/p\u003e\n"]]],[],null,["# Login URLs\n\nThe Users API provides functions for constructing URLs that allow the user to sign in or sign out, then be redirected back to your application.\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\n`UserService::createLoginUrl()` and `UserService::createLogoutUrl()` each take a destination URL for the application, and return a URL for signing in or signing out that redirects back to the given URL afterward. \n\n```php\nuse google\\appengine\\api\\users\\User;\nuse google\\appengine\\api\\users\\UserService;\n\n$user = UserService::getCurrentUser();\nif (isset($user)) {\n echo sprintf('Welcome, %s! (\u003ca href=\"%s\"\u003esign out\u003c/a\u003e)',\n $user-\u003egetNickname(),\n UserService::createLogoutUrl('/'));\n} else {\n echo sprintf('\u003ca href=\"%s\"\u003eSign in or register\u003c/a\u003e',\n UserService::createLoginUrl('/'));\n}\n```\n\nThe development web server simulates Google Accounts using its own sign-in and sign-out facilities. When you sign in to your application on the development web server, the server prompts you for an email address to use for the session. See [The Development Web Server](/appengine/docs/legacy/standard/php/tools/using-local-server) for more information.\n\n**Tip:** An easy way to restrict access to a part of your application to signed in users is to use the `login: required` configuration element for the URL handler. See [Configuring an App](/appengine/docs/legacy/standard/php/config/appref)."]]