本文整理汇总了PHP中CS50::getUser方法的典型用法代码示例。如果您正苦于以下问题:PHP CS50::getUser方法的具体用法?PHP CS50::getUser怎么用?PHP CS50::getUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CS50
的用法示例。
在下文中一共展示了CS50::getUser方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
<?php
/**
Login page. Compares entered password to the
user's password. Sets session id if successful.
**/
// configuration
require "../includes/config.php";
$user = CS50::getUser(RETURN_TO);
if ($user !== false) {
// query database for user
$rows = query("SELECT * FROM users WHERE name = ?", $user["identity"]);
// if we found user,
if (count($rows) == 1) {
// first (and only) row
$row = $rows[0];
// remember that user's now logged in by storing user's ID in session
$_SESSION["id"] = $row["id"];
//print("Logged in.");
// redirect to portfolio
redirect("/");
} else {
// insert new user into database
$result = query("INSERT INTO users (name, password, email, admin, realname) VALUES(?, ?, ?, 0, ?)", $user["identity"], "", $user["email"], $user["fullname"]);
// if user not added, notify user
if ($result === false) {
echo "The new user could not be added.";
}
//obtain most recently allocated user id
$rows = query("SELECT LAST_INSERT_ID() AS id");
$id = $rows[0]["id"];