Last active
January 2, 2016 10:59
-
-
Save cnevinc/8293418 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'google/appengine/api/users/UserService.php'; | |
use google\appengine\api\users\User; | |
use google\appengine\api\users\UserService; | |
$user = UserService::getCurrentUser(); // 如果使用者已經登入,此處的$user不為null | |
if ($user===null) { | |
header('Location: ' . // 如果未登入,將使用者導向登入頁面, | |
UserService::createLoginURL($_SERVER['REQUEST_URI'])); // 當登入成功後再導回來現在這個頁面($_SERVER['REQUEST_URI']) | |
exit; | |
} | |
// 如果已經登入,顯示使用者的暱稱以及以下內容 | |
?> | |
<html> | |
<head> | |
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" /> | |
</head> | |
<body> | |
<?php | |
echo 'Hello, [' . htmlspecialchars($user->getNickname()) ."] "; | |
echo 'Not you? <a href=' . UserService::createLogoutURL($_SERVER['REQUEST_URI']).">Sing Out</a>"."<BR>"; | |
// 一個簡單的form, 儲存POST過來的資料 | |
if (array_key_exists('content', $_POST)) { | |
echo "You wrote:<pre>\n"; | |
echo htmlspecialchars($_POST['content']); // htmlspecialchars讓所有特殊符號以html編碼方式呈現 | |
echo "\n</pre>"; | |
} | |
?> | |
<form action="/sign" method="post"> | |
<div><textarea name="content" rows="3" cols="60"></textarea></div> | |
<div><input type="submit" value="Sign Guestbook"></div> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment