本文整理汇总了PHP中setSession函数的典型用法代码示例。如果您正苦于以下问题:PHP setSession函数的具体用法?PHP setSession怎么用?PHP setSession使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setSession函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doLogin
/**
* 执行登录
*/
public function doLogin()
{
$condition['name'] = $username = trim($_POST['username']);
$condition['password'] = $password = md5(trim($_POST['password']));
//稍后在加验证码验证逻辑
//$imgCode = $_POST['imgCode'];
if (empty($username) || empty($password)) {
$this->ajaxReturn(null, C("ERR_MSG_70"), "success:false");
}
$user = D("User")->relation(true)->where($condition)->find();
if (empty($user)) {
$this->ajaxReturn(null, "用户名或者密码错误", "success:false");
}
if (empty($user['apps']) && $user['role'] != UserModel::ADMIN) {
$this->ajaxReturn(null, '该用户不属于任何一个APP,不允许登录,请联系管理员!', 'success:false');
}
if (empty($user)) {
$this->ajaxReturn(null, C("ERR_MSG_70"), "success:false");
}
$defaultAppId = $user['defaultApp'] >= 0 ? $user['defaultApp'] : $user['apps'][0]['id'];
foreach ($user['apps'] as $app) {
if ($app['id'] == $defaultAppId) {
$appName = $app['appName'];
break;
}
}
$session = array('uid' => $user['id'], 'username' => $username, 'role' => $user['role'], 'appId' => $defaultAppId, 'appName' => $appName);
setSession($session);
$this->ajaxReturn($data, "恭喜,登录成功!", "success:true");
}
示例2: authenticate
public function authenticate(SecurityContextInterface $context)
{
$token = $this->generateEmptyToken();
$client = null;
try {
$client = $this->userAuthenticationProvider->loadClientByCredentials($token->getClient()->getCredentials());
} catch (ClientCredentialsNotFoundException $e) {
$this->logger->addAlert('Client not found ' . $e->getMessage());
throw $e;
}
//validate the client, if good then add to the context
if (!is_null($client)) {
if ($this->statusIsLocked($client)) {
$this->container->get('EventDispatcher')->dispatch(__YML_KEY, 'login_status_locked', array('client' => $client));
setSession('_security_secured_area', null);
} elseif (!$this->checkPasswordsMatch($client->getPassword(), $token->getClient()->getPassword())) {
$this->container->get('EventDispatcher')->dispatch(__YML_KEY, 'login_password_mismatch', array('client' => $client));
} elseif (!$this->checkStatus($client)) {
$this->container->get('EventDispatcher')->dispatch(__YML_KEY, 'login_status_not_active', array('client' => $client));
}
$token->setClient($client);
}
$context->setToken($token);
setSession('_security_secured_area', serialize($token));
$this->container->set('securityContext', 'core\\components\\security\\core\\SecurityContext', $context);
}
示例3: authenticate
function authenticate($uid, $pwd)
{
/*if ($pwd)
{
$ds = ldap_connect("172.31.1.42");
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$a = ldap_search($ds, "dc=iiita,dc=ac,dc=in", "uid=$uid" );
$b = ldap_get_entries( $ds, $a );
if(count($b) > 1)
$dn = $b[0]["dn"];
else
return 0;
$ldapbind=@ldap_bind($ds, $dn, $pwd);
if ($ldapbind) {
return 1;
setSession($uid);
}
else
return 0;
ldap_close($ds);
}
else
return 0;*/
setSession($uid);
return 1;
}
示例4: Grid
function Grid()
{
$response = new ResponseManager();
$filterUser = Kit::GetParam('filterUser', _REQUEST, _STRING);
$filterEntity = Kit::GetParam('filterEntity', _REQUEST, _STRING);
$filterFromDt = Kit::GetParam('filterFromDt', _REQUEST, _STRING);
$filterToDt = Kit::GetParam('filterToDt', _REQUEST, _STRING);
setSession('auditlog', 'Filter', Kit::GetParam('XiboFilterPinned', _REQUEST, _CHECKBOX, 'off'));
setSession('auditlog', 'filterFromDt', $filterFromDt);
setSession('auditlog', 'filterToDt', $filterToDt);
setSession('auditlog', 'filterUser', $filterUser);
setSession('auditlog', 'filterEntity', $filterEntity);
$search = array();
// Get the dates and times
if ($filterFromDt == '') {
$fromTimestamp = new DateTime();
$fromTimestamp = $fromTimestamp->sub(new DateInterval("P1D"));
} else {
$fromTimestamp = DateTime::createFromFormat('Y-m-d', $filterFromDt);
$fromTimestamp->setTime(0, 0, 0);
}
if ($filterToDt == '') {
$toTimestamp = new DateTime();
} else {
$toTimestamp = DateTime::createFromFormat('Y-m-d', $filterToDt);
$toTimestamp->setTime(0, 0, 0);
}
$search[] = array('fromTimeStamp', $fromTimestamp->format('U'));
$search[] = array('toTimeStamp', $toTimestamp->format('U'));
if ($filterUser != '') {
$search[] = array('userName', $filterUser);
}
if ($filterEntity != '') {
$search[] = array('entity', $filterEntity);
}
// Build the search string
$search = implode(' ', array_map(function ($element) {
return implode('|', $element);
}, $search));
$cols = array(array('name' => 'logId', 'title' => __('ID')), array('name' => 'logDate', 'title' => __('Date')), array('name' => 'userName', 'title' => __('User')), array('name' => 'entity', 'title' => __('Entity')), array('name' => 'message', 'title' => __('Message')), array('name' => 'objectAfter', 'title' => __('Object'), 'array' => true));
Theme::Set('table_cols', $cols);
$rows = \Xibo\Factory\AuditLogFactory::query('logId', array('search' => $search));
// Do some post processing
foreach ($rows as $row) {
/* @var \Xibo\Entity\AuditLog $row */
$row->logDate = DateManager::getLocalDate($row->logDate);
$row->objectAfter = json_decode($row->objectAfter);
}
Theme::Set('table_rows', json_decode(json_encode($rows), true));
$output = Theme::RenderReturn('table_render');
$response->initialSortOrder = 2;
$response->initialSortColumn = 1;
$response->pageSize = 20;
$response->SetGridResponse($output);
$response->Respond();
}
示例5: setDefaultLocale
public function setDefaultLocale($locale)
{
$userPreferences = getSession('userPreferences');
if (is_null($userPreferences) || !is_array($userPreferences)) {
$userPreferences = array();
}
$locales = $this->httpRequest->getAttribute('locales');
$userPreferences['defaultLocale'] = $locales[$locale];
setSession('userPreferences', $userPreferences);
}
示例6: Grid
function Grid()
{
$db =& $this->db;
$user =& $this->user;
$response = new ResponseManager();
$type = Kit::GetParam('filter_type', _POST, _WORD);
$fromdt = Kit::GetParam('filter_fromdt', _POST, _STRING);
///get the dates and times
if ($fromdt != '') {
$start_date = explode("/", $fromdt);
// dd/mm/yyyy
$starttime_timestamp = strtotime($start_date[1] . "/" . $start_date[0] . "/" . $start_date[2] . ' ' . date("H", time()) . ":" . date("i", time()) . ':59');
}
setSession('sessions', 'Filter', Kit::GetParam('XiboFilterPinned', _REQUEST, _CHECKBOX, 'off'));
setSession('sessions', 'filter_type', $type);
setSession('sessions', 'filter_fromdt', $fromdt);
$SQL = "SELECT session.userID, user.UserName, IsExpired, LastPage, session.LastAccessed, RemoteAddr, UserAgent ";
$SQL .= "FROM `session` LEFT OUTER JOIN user ON user.userID = session.userID ";
$SQL .= "WHERE 1 = 1 ";
if ($fromdt != '') {
$SQL .= sprintf(" AND session_expiration < '%s' ", $starttime_timestamp);
}
if ($type == "active") {
$SQL .= " AND IsExpired = 0 ";
}
if ($type == "expired") {
$SQL .= " AND IsExpired = 1 ";
}
if ($type == "guest") {
$SQL .= " AND session.userID IS NULL ";
}
// Load results into an array
$log = $db->GetArray($SQL);
if (!is_array($log)) {
trigger_error($db->error());
trigger_error(__('Error getting the log'), E_USER_ERROR);
}
$rows = array();
foreach ($log as $row) {
$row['userid'] = Kit::ValidateParam($row['userID'], _INT);
$row['username'] = Kit::ValidateParam($row['UserName'], _STRING);
$row['isexpired'] = Kit::ValidateParam($row['IsExpired'], _INT) == 0 ? 'icon-ok' : 'icon-remove';
$row['lastpage'] = Kit::ValidateParam($row['LastPage'], _STRING);
$row['lastaccessed'] = Kit::ValidateParam($row['LastAccessed'], _STRING);
$row['ip'] = Kit::ValidateParam($row['RemoteAddr'], _STRING);
$row['browser'] = Kit::ValidateParam($row['UserAgent'], _STRING);
// Edit
$row['buttons'][] = array('id' => 'sessions_button_logout', 'url' => 'index.php?p=sessions&q=ConfirmLogout&userid=' . $row['userid'], 'text' => __('Logout'));
$rows[] = $row;
}
Theme::Set('table_rows', $rows);
$output = Theme::RenderReturn('sessions_page_grid');
$response->SetGridResponse($output);
$response->Respond();
}
示例7: TemplateView
/**
* Data grid
*/
function TemplateView()
{
$db =& $this->db;
$user =& $this->user;
$response = new ResponseManager();
$filter_name = Kit::GetParam('filter_name', _POST, _STRING);
$filter_tags = Kit::GetParam('filter_tags', _POST, _STRING);
setSession('template', 'filter_name', $filter_name);
setSession('template', 'filter_tags', $filter_tags);
setSession('template', 'Filter', Kit::GetParam('XiboFilterPinned', _REQUEST, _CHECKBOX, 'off'));
// Show filter_showThumbnail
$showThumbnail = Kit::GetParam('showThumbnail', _POST, _CHECKBOX);
setSession('layout', 'showThumbnail', $showThumbnail);
$templates = $user->TemplateList(null, array('layout' => $filter_name, 'tags' => $filter_tags));
if (!is_array($templates)) {
trigger_error(__('Unable to get list of templates for this user'), E_USER_ERROR);
}
$cols = array(array('name' => 'layout', 'title' => __('Name')), array('name' => 'owner', 'title' => __('Owner')), array('name' => 'descriptionWithMarkup', 'title' => __('Description')), array('name' => 'thumbnail', 'title' => __('Thumbnail'), 'hidden' => $showThumbnail == 0), array('name' => 'permissions', 'title' => __('Permissions')));
Theme::Set('table_cols', $cols);
$rows = array();
foreach ($templates as $template) {
$template['permissions'] = $this->GroupsForTemplate($template['campaignid']);
$template['owner'] = $user->getNameFromID($template['ownerid']);
$template['thumbnail'] = '';
if ($showThumbnail == 1 && $template['backgroundImageId'] != 0) {
$template['thumbnail'] = '<a class="img-replace" data-toggle="lightbox" data-type="image" data-img-src="index.php?p=module&mod=image&q=Exec&method=GetResource&mediaid=' . $template['backgroundImageId'] . '&width=100&height=100&dynamic=true&thumb=true" href="index.php?p=module&mod=image&q=Exec&method=GetResource&mediaid=' . $template['backgroundImageId'] . '"><i class="fa fa-file-image-o"></i></a>';
}
$template['buttons'] = array();
// Parse down for description
$template['descriptionWithMarkup'] = Parsedown::instance()->text($template['description']);
if ($template['edit']) {
// Edit Button
$template['buttons'][] = array('id' => 'template_button_edit', 'url' => 'index.php?p=template&q=EditForm&modify=true&layoutid=' . $template['layoutid'], 'text' => __('Edit'));
}
if ($template['del']) {
// Delete Button
$template['buttons'][] = array('id' => 'layout_button_delete', 'url' => 'index.php?p=template&q=DeleteTemplateForm&layoutid=' . $template['layoutid'], 'text' => __('Delete'));
}
if ($template['modifyPermissions']) {
// Permissions Button
$template['buttons'][] = array('id' => 'layout_button_delete', 'url' => 'index.php?p=campaign&q=PermissionsForm&CampaignID=' . $template['campaignid'], 'text' => __('Permissions'));
}
$template['buttons'][] = array('linkType' => 'divider');
// Export Button
$template['buttons'][] = array('id' => 'layout_button_export', 'linkType' => '_self', 'url' => 'index.php?p=layout&q=Export&layoutid=' . $template['layoutid'], 'text' => __('Export'));
// Add this row to the array
$rows[] = $template;
}
Theme::Set('table_rows', $rows);
$response->SetGridResponse(Theme::RenderReturn('table_render'));
$response->Respond();
}
示例8: authenticate
function authenticate($username, $password)
{
$passwordcrypt = ENCRYPT . $password;
$passwordcrypt = SHA1($passwordcrypt);
$sql = "SELECT * FROM users WHERE username = :username AND password = :password AND isactive = 1 AND isdeleted = 0";
$params = array(':username' => $username, ':password' => $passwordcrypt);
$result = DatabaseHandler::GetAll($sql, $params);
if (count($result) > 0) {
setSession($username);
return 1;
}
return 0;
}
示例9: login
function login($userid, $userpassword)
{
//check password for login
$password = getUserpassword($userid);
if (empty($password)) {
echo "ID not found!";
} else {
if ($password == $userpassword) {
echo "login success!";
setSession($userid, getUsername($userid), getUsertype($userid));
}
}
}
示例10: Grid
function Grid()
{
$db =& $this->db;
$response = new ResponseManager();
$type = Kit::GetParam('filter_type', _POST, _WORD);
$fromDt = Kit::GetParam('filter_fromdt', _POST, _STRING);
setSession('sessions', 'Filter', Kit::GetParam('XiboFilterPinned', _REQUEST, _CHECKBOX, 'off'));
setSession('sessions', 'filter_type', $type);
setSession('sessions', 'filter_fromdt', $fromDt);
$SQL = "SELECT session.userID, user.UserName, IsExpired, LastPage, session.LastAccessed, RemoteAddr, UserAgent ";
$SQL .= "FROM `session` LEFT OUTER JOIN user ON user.userID = session.userID ";
$SQL .= "WHERE 1 = 1 ";
if ($fromDt != '') {
// From Date is the Calendar Formatted DateTime in ISO format
$SQL .= sprintf(" AND session.LastAccessed < '%s' ", DateManager::getMidnightSystemDate(DateManager::getTimestampFromString($fromDt)));
}
if ($type == "active") {
$SQL .= " AND IsExpired = 0 ";
}
if ($type == "expired") {
$SQL .= " AND IsExpired = 1 ";
}
if ($type == "guest") {
$SQL .= " AND session.userID IS NULL ";
}
// Load results into an array
$log = $db->GetArray($SQL);
Debug::LogEntry('audit', $SQL);
if (!is_array($log)) {
trigger_error($db->error());
trigger_error(__('Error getting the log'), E_USER_ERROR);
}
$cols = array(array('name' => 'lastaccessed', 'title' => __('Last Accessed')), array('name' => 'isexpired', 'title' => __('Active'), 'icons' => true), array('name' => 'username', 'title' => __('User Name')), array('name' => 'lastpage', 'title' => __('Last Page')), array('name' => 'ip', 'title' => __('IP Address')), array('name' => 'browser', 'title' => __('Browser')));
Theme::Set('table_cols', $cols);
$rows = array();
foreach ($log as $row) {
$row['userid'] = Kit::ValidateParam($row['userID'], _INT);
$row['username'] = Kit::ValidateParam($row['UserName'], _STRING);
$row['isexpired'] = Kit::ValidateParam($row['IsExpired'], _INT) == 1 ? 0 : 1;
$row['lastpage'] = Kit::ValidateParam($row['LastPage'], _STRING);
$row['lastaccessed'] = DateManager::getLocalDate(strtotime(Kit::ValidateParam($row['LastAccessed'], _STRING)));
$row['ip'] = Kit::ValidateParam($row['RemoteAddr'], _STRING);
$row['browser'] = Kit::ValidateParam($row['UserAgent'], _STRING);
// Edit
$row['buttons'][] = array('id' => 'sessions_button_logout', 'url' => 'index.php?p=sessions&q=ConfirmLogout&userid=' . $row['userid'], 'text' => __('Logout'));
$rows[] = $row;
}
Theme::Set('table_rows', $rows);
$response->SetGridResponse(Theme::RenderReturn('table_render'));
$response->Respond();
}
示例11: register
public function register()
{
// $registerForm=I('post.registerForm');
$registerForm['username'] = I('post.username');
$registerForm['email'] = I('post.email');
$registerForm['password'] = md5(I('post.password'));
if (I('post.password') == I('post.retype-password')) {
$this->_User->create($registerForm);
$result = $this->_User->add();
if ($result) {
setSession($result, $registerForm['username']);
} else {
}
}
echo I('post.username');
}
示例12: getAction
public function getAction()
{
if (empty($_SERVER['HTTP_X_REQUESTED_WITH'])) {
error404();
}
$model = new ChatModel();
$dialog = '';
$userList = '';
$lastMessageID = getSession('chat_lmid', false);
$chatList = $model->getChatMessages('chat', 'ASC', $lastMessageID);
if ($chatList) {
foreach ($chatList as $value) {
$msg = ' ' . $value['message'];
if (strpos($msg, Request::getParam('user')->nickname) !== false) {
$color = ' chat_your_msg';
} else {
$color = false;
}
$dialog .= '<div class="chat_message' . $color . '">' . '<div class="chat_img"><a href="' . url($value['uid']) . '" target="_blank"><img src="' . getAvatar($value['uid'], 's') . '"></a></div>' . '<div class="chat_text">' . '<div><span class="chat_nickname" onclick="chatNickname(\'' . $value['uName'] . '\');">' . $value['uName'] . '</span> <span class="chat_time">' . printTime($value['time']) . '</span></div>' . '<div>' . $value['message'] . '</div>' . '</div>' . '</div>';
setSession('chat_lmid', $value['id']);
}
}
unset($chatList);
/*
if (time()%5 == 0 OR getSession('chat_ses') == 0) {
$listUserOnline = $model->getUserOnline();
$countUser = 0;
while ($list = mysqli_fetch_object($listUserOnline)) {
$userList .= '<li><a href="' . url($list->id) . '" target="_blank"><span>' . $list->nickname . '</span><span class="level-icon">' . $list->level . '</span></a></li>';
$countUser++;
}
$response['userList'] = $userList;
$response['countUser'] = $countUser;
}
*/
$response['error'] = 0;
if ($dialog) {
$response['target_a']['#dialog'] = $dialog;
}
setSession('chat_ses', 1);
echo json_encode($response);
exit;
}
示例13: login
/**
* 验证登录
*/
public function login($params = array())
{
$db = Yii::$app->db;
// validate
if (!$this->load($params) && !$this->validate()) {
return false;
}
$model_name = getClassName(get_class($this));
$data = $params[$model_name];
if (!$data['captcha'] || $data['captcha'] != getSession('__captcha/login/captcha')) {
//showMessage('验证码错误!');
return false;
}
$sql = 'select username from forum_account where username="' . $data['username'] . '" and password = "' . md5($data['password']) . '" limit 1';
$command = $db->createCommand($sql);
$data = $command->queryOne();
if ($data) {
setSession('username', $data['username']);
return true;
} else {
return false;
}
}
示例14: CategoryGrid
/**
* Category Grid
*/
function CategoryGrid()
{
$user =& $this->user;
$response = new ResponseManager();
setSession('category', 'CategoryFilter', Kit::GetParam('XiboFilterPinned', _REQUEST, _CHECKBOX, 'off'));
// Show enabled
$filterEnabled = Kit::GetParam('filterEnabled', _POST, _INT);
setSession('category', 'filterEnabled', $filterEnabled);
$rows = $user->CategoryList(array('category'), array('enabled' => $filterEnabled));
$categorys = array();
$cols = array(array('name' => 'categoryid', 'title' => __('ID')), array('name' => 'category', 'title' => __('Category')));
Theme::Set('table_cols', $cols);
foreach ($rows as $row) {
// Edit Button
$row['buttons'][] = array('id' => 'category_button_edit', 'url' => 'index.php?p=category&q=EditForm&categoryid=' . $row['categoryid'], 'text' => __('Edit'));
// Delete Button
$row['buttons'][] = array('id' => 'category_button_delete', 'url' => 'index.php?p=category&q=DeleteForm&categoryid=' . $row['categoryid'], 'text' => __('Delete'));
// Add to the rows objects
$categorys[] = $row;
}
Theme::Set('table_rows', $categorys);
$response->SetGridResponse(Theme::RenderReturn('table_render'));
$response->Respond();
}
示例15: TemplateView
/**
* Data grid
*/
function TemplateView()
{
$db =& $this->db;
$user =& $this->user;
$response = new ResponseManager();
$filter_name = Kit::GetParam('filter_name', _POST, _STRING);
$filter_tags = Kit::GetParam('filter_tags', _POST, _STRING);
$filter_is_system = Kit::GetParam('filter_is_system', _POST, _INT);
setSession('template', 'filter_name', $filter_name);
setSession('template', 'filter_tags', $filter_tags);
setSession('template', 'filter_is_system', $filter_is_system);
setSession('template', 'Filter', Kit::GetParam('XiboFilterPinned', _REQUEST, _CHECKBOX, 'off'));
$templates = $user->TemplateList($filter_name, $filter_tags, $filter_is_system);
if (!is_array($templates)) {
trigger_error(__('Unable to get list of templates for this user'), E_USER_ERROR);
}
$rows = array();
foreach ($templates as $template) {
$template['permissions'] = $this->GroupsForTemplate($template['templateid']);
$template['owner'] = $user->getNameFromID($template['ownerid']);
$template['buttons'] = array();
if ($template['del'] && $template['issystem'] == 'No') {
// Delete Button
$template['buttons'][] = array('id' => 'layout_button_delete', 'url' => 'index.php?p=template&q=DeleteTemplateForm&templateid=' . $template['templateid'], 'text' => __('Delete'));
}
if ($template['modifyPermissions'] && $template['issystem'] == 'No') {
// Permissions Button
$template['buttons'][] = array('id' => 'layout_button_delete', 'url' => 'index.php?p=template&q=PermissionsForm&templateid=' . $template['templateid'], 'text' => __('Permissions'));
}
// Add this row to the array
$rows[] = $template;
}
Theme::Set('table_rows', $rows);
$response->SetGridResponse(Theme::RenderReturn('template_page_grid'));
$response->Respond();
}