本文整理汇总了PHP中Session::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::add方法的具体用法?PHP Session::add怎么用?PHP Session::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Session
的用法示例。
在下文中一共展示了Session::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: indexAction
public function indexAction()
{
$session = new Session();
$session->add('name', 'php');
$session->add('type', 'web');
var_dump($_SESSION);
$session->remove('name');
var_dump($_SESSION);
// 移去所有session变量
$session->clear();
// 移去存储在服务器端的数据
$session->destroy();
// $session->close();
var_dump($_SESSION);
}
示例2: validar
/**
* Método encargado de validar datos
* @param Array $array Datos a validar
* @return Boolean true = si los datos son validos, false = si son invalidos
*/
public static function validar($array)
{
// Validación de la clave
if (isset($array['clave'])) {
if (($erro = Validaciones::validarPassLogin($array["clave"])) !== true) {
Session::addArray('feedback_negative', $erro);
}
} else {
Session::add('feedback_negative', 'No se ha indicado la clave');
}
// Validación del email
if (isset($array['email'])) {
if (($erro = Validaciones::validarEmail($array["email"])) !== true) {
Session::addArray('feedback_negative', $erro);
}
} else {
Session::add('feedback_negative', 'No se ha indicado el email');
}
// Si hay errores devolvemos false
if (Session::get('feedback_negative')) {
return false;
}
// Si no hay errores devolvemos true
return true;
}
示例3: login
public static function login()
{
// validate the length
if (strlen(Request::post('login_name')) < 2 || strlen(Request::post('login_name')) > 20 || strlen(Request::post('login_password')) < 8 || strlen(Request::post('login_password')) > 255) {
// give the same feedback that's on wrong user name to not give out any data
Session::add('feedback_negative', 'Error. Username or password wrong.');
return false;
}
// get user details
$user = self::getUserData('user_name', Request::post('login_name'));
// if there's no user with given name
if (!$user) {
Session::add('feedback_negative', 'Error. Username or password wrong.');
return false;
}
// check if password ok
if (!password_verify(Request::post('login_password'), $user->user_password)) {
// give the same feedback that's on wrong user name to not give out any data
Session::add('feedback_negative', 'Error. Username or password wrong.');
return false;
}
// set session variables
Session::set('user_id', $user->user_id);
Session::set('user_name', $user->user_name);
Session::set('user_permissions', $user->user_permissions);
// set user as logged-in
Session::set('user_logged_in', true);
return true;
}
示例4: edit
public static function edit($datos)
{
$conn = Database::getInstance()->getDatabase();
$errores_validacion = false;
if (empty($datos['id_pregunta'])) {
Session::add('feedback_negative', 'No he recibido la pregunta');
$errores_validacion = true;
}
if (empty($datos['asunto'])) {
Session::add('feedback_negative', "No he recibido el asunto de la pregunta");
$errores_validacion = true;
}
if (empty($datos['cuerpo'])) {
Session::add('feedback_negative', "No he recibido el cuerpo de la pregunta");
$errores_validacion = true;
}
if ($errores_validacion) {
return false;
} else {
$ssql = "UPDATE pregunta SET asunto=:asunto, cuerpo=:cuerpo WHERE id_pregunta=:id";
$query = $conn->prepare($ssql);
$parameters = array(':asunto' => $datos["asunto"], ':cuerpo' => $datos["cuerpo"], ':id' => $datos["id_pregunta"]);
$query->execute($parameters);
$count = $query->rowCount();
if ($count == 1) {
Session::add('feedback_positive', 'Editado con éxito, gracias!!!');
return true;
}
Session::add('feedback_positive', 'Actualizadas 0 casillas');
return false;
}
}
示例5: appendNotesHelpRequest
/**
* @function appendNotesHelpRequest
* @public
* @static
* @returns {boolean} True if successful.
* @desc Adds notes from tutor input, into a record of a help request.
* @param {integer} $id The unique identity for the help request.
* @param {string} $noteDD The ``quick'' option of filling in notes for a help request.
* @param {string} $noteText The type option of filling in notes of a help request.
* @example NONE
*/
public static function appendNotesHelpRequest($id, $noteDD, $noteText)
{
$database = DatabaseFactory::getFactory()->getConnection();
$query = $database->prepare("UPDATE qscQueue.tblRequests SET notesDropDown = :note_drop_down, notesEditable = :note_text WHERE id = :id_no");
$query->execute(array(':note_drop_down' => $noteDD, ':note_text' => $noteText, ':id_no' => $id));
Session::add('feedback_positive', 'added the notes to a help request - success');
return true;
}
示例6: resetUserSession
/**
* Kicks the selected user out of the system instantly by resetting the user's session.
* This means, the user will be "logged out".
*
* @param $userId
* @return bool
*/
private static function resetUserSession($userId)
{
$database = DatabaseFactory::getFactory()->getConnection();
$query = $database->prepare("UPDATE users SET session_id = :session_id WHERE user_id = :user_id LIMIT 1");
$query->execute(array(':session_id' => null, ':user_id' => $userId));
if ($query->rowCount() == 1) {
Session::add('feedback_positive', Text::get('FEEDBACK_ACCOUNT_USER_SUCCESSFULLY_KICKED'));
return true;
}
}
示例7: removePerm
/**
* Remove A user permission
* @param $user_id
* @param $removed_perm
*/
public static function removePerm($user_id, $removed_perm)
{
if (self::$removePermQuery === null) {
self::$removePermQuery = DatabaseFactory::getFactory()->getConnection()->prepare("UPDATE users SET perms = :new WHERE user_id = :user_id");
}
$original = UserRoleModel::getPerms($user_id);
$being_removed = array_search($removed_perm, $original);
unset($original[$being_removed]);
self::$removePermQuery->execute(array(':new' => json_encode($original), ':user_id' => $user_id));
Session::add('feedback_positive', 'Removed that permission!');
}
示例8: createShort
public static function createShort($url)
{
try {
$code = ShortModel::urlToShortCode($url);
Session::add('feedback_positive', 'SUCCESS! SHORT URL: ' . ShortModel::$shortUrlPrefix . $code);
return true;
} catch (Exception $e) {
// log exception and then redirect to error page.
Session::add('feedback_negative', 'URL SHORTENING FAILED');
return false;
}
}
示例9: setRequestDetails
/**
* @function setRequestDetails
* @public
* @static
* @returns NONE
* @desc
* @param {string} foo Use the 'foo' param for bar.
* @example NONE
*/
public static function setRequestDetails($recordID, $tableNo, $subj, $subSubj, $tutName)
{
$database = DatabaseFactory::getFactory()->getConnection();
// to do = update according to the settings needed given func's params/args.
$query = $database->prepare("UPDATE users SET user_deleted = :user_deleted WHERE user_id = :user_id LIMIT 1");
$query->execute(array(':user_deleted' => $delete, ':user_id' => $userId));
// to do = determine if needed below if-statement
if ($query->rowCount() == 1) {
Session::add('feedback_positive', Text::get('FEEDBACK_ACCOUNT_SUSPENSION_DELETION_STATUS'));
return true;
}
}
示例10: menuIsActive
public static function menuIsActive()
{
if (!Session::getNested('active_menu', 'menu_id')) {
// destroy session
// Session::destroy();
//
// create error message
Session::add('feedback_errors', ErrorMessage::get('MENU_NOT_ACTIVE'));
// redirect to menu selection screen
header('Location: ' . URL_WITH_INDEX_FILE . 'menumanager/managemenus');
exit;
}
}
示例11: deleteNote
/**
* Delete a specific note
* @param int $note_id id of the note
* @return bool feedback (was the note deleted properly ?)
*/
public static function deleteNote($note_id)
{
if (!$note_id) {
return false;
}
$note = NoteQuery::create()->findPK($note_id);
$note->delete();
if ($note) {
return true;
}
// default return
Session::add('feedback_negative', Text::get('FEEDBACK_NOTE_DELETION_FAILED'));
return false;
}
示例12: changeUserRole
/**
* Upgrades / downgrades the user's account. Currently it's just the field user_account_type in the database that
* can be 1 or 2 (maybe "basic" or "premium"). Put some more complex stuff in here, maybe a pay-process or whatever
* you like.
*
* @param $type
*
* @return bool
*/
public static function changeUserRole($type)
{
if (!$type) {
return false;
}
// save new role to database
if (self::saveRoleToDatabase($type)) {
Session::add('feedback_positive', Text::get('FEEDBACK_ACCOUNT_TYPE_CHANGE_SUCCESSFUL'));
return true;
} else {
Session::add('feedback_negative', Text::get('FEEDBACK_ACCOUNT_TYPE_CHANGE_FAILED'));
return false;
}
}
示例13: addSelect
public function addSelect()
{
if (empty($_POST['check_list_Material']) || empty($_POST['oeuvre_id'])) {
Session::add('feedback_negative', 'Tiene que escoger una de tus obras y seleccionar algún material');
Redirect::to('dashboard/index');
} else {
$arrayIdMaterial = $_POST['check_list_Material'];
$oeuvre_id = $_POST['oeuvre_id'];
foreach ($arrayIdMaterial as $value) {
DashboardModel::addMaterialToOeuvre($oeuvre_id, $value);
}
Session::add('feedback_positive', 'Se ha añadido correctamente en tu obra señalada los materiales señalados');
Redirect::to('dashboard/index');
}
}
示例14: getPublicProfileOfUser
/**
* @function getPublicProfileOfUser
* @public
* @static
* @returns {array} A single user profile.
* @desc Gets a user's profile data, according to the given $user_id.
* @param {integer} $user_id The user's id.
* @example NONE
*/
public static function getPublicProfileOfUser($user_id)
{
$database = DatabaseFactory::getFactory()->getConnection();
$sql = "SELECT user_id, user_name, user_email, user_active, user_deleted FROM users WHERE user_id = :user_id LIMIT 1";
$query = $database->prepare($sql);
$query->execute(array(':user_id' => $user_id));
$user = $query->fetch();
if ($query->rowCount() != 1) {
Session::add('feedback_negative', Text::get('FEEDBACK_USER_DOES_NOT_EXIST'));
}
// all elements of array passed to Filter::XSSFilter for XSS sanitation, have a look into
// application/core/Filter.php for more info on how to use. Removes (possibly bad) JavaScript etc from
// the user's values
array_walk_recursive($user, 'Filter::XSSFilter');
return $user;
}
示例15: setAccountDeletionStatus
/**
* @function setAccountDeletionStatus
* @public
* @static
* @returns NONE
* @desc
* @param {string} foo Use the 'foo' param for bar.
* @example NONE
*/
public static function setAccountDeletionStatus($softDelete, $userId)
{
$database = DatabaseFactory::getFactory()->getConnection();
// FYI "on" is what a checkbox delivers by default when submitted.
if ($softDelete == "on") {
$delete = 1;
} else {
$delete = 0;
}
$query = $database->prepare("UPDATE users SET user_deleted = :user_deleted WHERE user_id = :user_id LIMIT 1");
$query->execute(array(':user_deleted' => $delete, ':user_id' => $userId));
if ($query->rowCount() == 1) {
Session::add('feedback_positive', Text::get('FEEDBACK_ACCOUNT_SUSPENSION_DELETION_STATUS'));
return true;
}
}