本文整理汇总了PHP中startSession函数的典型用法代码示例。如果您正苦于以下问题:PHP startSession函数的具体用法?PHP startSession怎么用?PHP startSession使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了startSession函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loggedInOrRedirect
function loggedInOrRedirect()
{
startSession();
if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true) {
die(header('Location: login.php'));
}
}
示例2: checkFormToken
function checkFormToken($tokenName, $formTokenValue){
startSession();
if ($formTokenValue != $_SESSION[$tokenName]){
exit('ERROR: invalid form token! Do not submit your form twice.');
}
unset($_SESSION[$tokenName]);
}
示例3: logOut
function logOut()
{
startSession();
$_SESSION['id'] = '';
$_SESSION['username'] = '';
session_destroy();
header("Location: index.php");
}
示例4: saveSession
function saveSession($email, $usertype, $firstname, $lastname, $userid)
{
startSession();
$_SESSION['userid'] = $userid;
$_SESSION['firstname'] = $firstname;
$_SESSION['lastname'] = $lastname;
$_SESSION['email'] = $email;
$_SESSION['usertype'] = $usertype;
}
示例5: loginAction
function loginAction()
{
$email = $_POST['email'];
$pass = $_POST['password'];
$remember = $_POST['rememberData'];
$result = login($email);
if ($result['message'] == 'OK') {
$key = pack('H*', "bcb04b7e103a05afe34763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3");
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
# --- DECRYPTION ---
$ciphertext_dec = base64_decode($result['password']);
$iv_dec = substr($ciphertext_dec, 0, $iv_size);
$ciphertext_dec = substr($ciphertext_dec, $iv_size);
$plaintext_dec = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $ciphertext_dec, MCRYPT_MODE_CBC, $iv_dec);
$count = 0;
$length = strlen($plaintext_dec);
for ($i = $length - 1; $i >= 0; $i--) {
if (ord($plaintext_dec[$i]) === 0) {
$count++;
}
}
$plaintext_dec = substr($plaintext_dec, 0, $length - $count);
if ($plaintext_dec === $pass) {
$response = array('fName' => $result['fName'], 'lName' => $result['lName']);
# Starting the sesion (At the server)
startSession($result['fName'], $result['lName'], $result['email']);
$inTwoMonths = 60 * 60 * 24 * 60 + time();
# Setting the cookies
if ($remember) {
setcookie("cookieUsername", $result['email'], $inTwoMonths);
setcookie("cookiePassword", $result['password'], $inTwoMonths);
} else {
//if (isset($_COOKIE['cookieUsername']) && isset(($_COOKIE['cookiePassword']))) {
unset($_COOKIE['cookieUsername']);
unset($_COOKIE['cookiePassword']);
//}
}
echo json_encode($response);
} else {
die(json_encode(errors(206)));
}
} else {
die(json_encode($result));
}
}
示例6: formulaireIdentification
function formulaireIdentification()
{
startSession();
if ($_SESSION["connu"] === true) {
printSession();
} else {
if (!isset($_POST["submit_login"])) {
print_login_form();
} else {
$resultat = login($_POST["mail"], $_POST["mdp"]);
if ($resultat === true) {
printSession();
echo "Authentification réussie.</br>\n";
} else {
print_login_form();
echo "Mauvais mail ou mot de passe.</br>";
}
}
}
}
示例7: bootswatchFeedback
/**
* shows a quick user message (flash/heads up) to provide user feedback
*
* Uses a Session to store the data until the data is displayed via bootswatchFeedback()
*
* Related feedback() function used to store message
*
* <code>
* echo bootswatchFeedback(); #will show then clear message stored via feedback()
* </code>
*
* @param none
* @return string html & potentially CSS to style feedback
* @see feedback()
* @todo none
*/
function bootswatchFeedback()
{
startSession();
//startSession() does not return true in INTL APP!
$myReturn = "";
//init
if (isset($_SESSION['feedback']) && $_SESSION['feedback'] != "") {
#show message, clear flash
if (isset($_SESSION['feedback-level'])) {
$level = $_SESSION['feedback-level'];
} else {
$level = '';
}
switch ($level) {
case 'warning':
$level = 'warning';
break;
case 'info':
case 'notice':
$level = 'info';
break;
case 'success':
$level = 'success';
break;
case 'error':
case 'danger':
$level = 'danger';
break;
}
$myReturn .= '
<div class="alert alert-dismissable alert-' . $level . '" style="margin-top:.5em;">
<button class="close" data-dismiss="alert" type="button">×</button>
' . $_SESSION['feedback'] . '</div>
';
$_SESSION['feedback'] = "";
#cleared
$_SESSION['feedback-level'] = "";
}
return $myReturn;
//data passed back for printing
}
示例8: action
public static function action()
{
// 注册AUTOLOAD方法
spl_autoload_register(['self', 'autoload']);
define('_DOMAIN_', empty($_SERVER["HTTP_HOST"]) ? 'api.grlend.com' : $_SERVER["HTTP_HOST"]);
ini_set('date.timezone', 'Asia/Shanghai');
// 设置时区
ini_set("display_errors", "On");
error_reporting(E_ALL);
header("Content-type:text/html;charset=utf-8");
header("PowerBy: Han-zi,Liang");
header("F-Version: 1.0");
//框架版本
//载入防xss和sql注入文件
require_once 'waf.php';
//载入系统函数
require_once 'function.php';
startSession();
//启动程序
self::start();
}
示例9: fillSession
function fillSession($array)
{
startSession();
$err = fullCheck($array);
if ($err != "") {
return $err;
}
if (!isset($array["connu"])) {
sessionFillDefault();
return "Pofil inconnu.</br>\n";
}
if ($array["connu"] === false) {
sessionFillDefault();
return;
}
foreach ($varNames as $name) {
//echo '$_SESSION['.$name.'] = $array['.$name.'];</br>\n';
$_SESSION[$name] = $array[$name];
}
$_SESSION["connu"] = $array["connu"];
return "";
}
示例10: validateUser
function validateUser($username, $password)
{
$conn = connectToDataBase();
$sql = "SELECT * FROM User WHERE userName = \"" . $username . "\" AND userPassword = \"" . $password . "\"";
$result = mysqli_query($conn, $sql);
$array = array();
if (mysqli_num_rows($result) > 0) {
$array["response"] = "accepted";
$sql = "SELECT rolId, institutionId\n FROM HasRole hr, WorksInInstitution wi\n WHERE hr.userName = \"" . $username . "\" AND\n hr.userName = wi.userName;";
$result = mysqli_query($conn, $sql);
if ($row = mysqli_fetch_assoc($result)) {
$array["rolId"] = $row["rolId"];
$array["institutionId"] = $row["institutionId"];
$array["userName"] = $username;
startSession($array);
}
} else {
$array["response"] = "declined";
}
closeDb($conn);
echo json_encode($array);
}
示例11: showFeedback
/**
* shows a quick user message (flash/heads up) to provide user feedback
*
* Uses a Session to store the data until the data is displayed via showFeedback()
*
* Related feedback() function used to store message
*
* <code>
* echo showFeedback(); #will show then clear message stored via feedback()
* </code>
*
* changed from showFeedback() version 2.10
*
* @param none
* @return string html & potentially CSS to style feedback
* @see feedback()
* @todo none
*/
function showFeedback()
{
startSession();
//startSession() does not return true in INTL APP!
$myReturn = "";
//init
if (isset($_SESSION['feedback']) && $_SESSION['feedback'] != "") {
#show message, clear flash
if (defined('THEME_PHYSICAL') && file_exists(THEME_PHYSICAL . 'feedback.css')) {
//check to see if feedback.css exists - if it does use that
$myReturn .= '<link href="' . THEME_PATH . 'feedback.css" rel="stylesheet" type="text/css" />' . PHP_EOL;
} else {
//create css for feedback
$myReturn .= '
<style type="text/css">
.feedback { /* default style for div */
border: 1px solid #000;
margin:auto;
width:100%;
text-align:center;
font-weight: bold;
}
.error {
color: #000;
background-color: #ee5f5b; /* error color */
}
.warning {
color: #000;
background-color: #f89406; /* warning color */
}
.notice {
color: #000;
background-color: #5bc0de; /* notice color */
}
.success {
color: #000;
background-color: #62c462; /* notice color */
}
</style>
';
}
if (isset($_SESSION['feedback-level'])) {
$level = $_SESSION['feedback-level'];
} else {
$level = 'warning';
}
$myReturn .= '<div class="feedback ' . $level . '">' . $_SESSION['feedback'] . '</div>';
$_SESSION['feedback'] = "";
#cleared
$_SESSION['feedback-level'] = "";
return $myReturn;
//data passed back for printing
}
}
示例12: securePage
function securePage()
{
global $conf;
// If the sessionID is not present start the session (reading the
// users cookie and loading their settings from disk)
if (ONA_SESSION_ID != "") {
startSession();
}
// Make sure their session is still active
if (!isset($_SESSION['ona']['auth']['user']['username'])) {
//header("Location: {$https}{$baseURL}/login.php?expired=1");
exit;
}
return 0;
}
示例13:
include 'includes/header.php';
?>
<h1><?php
echo $pageID;
?>
</h1>
<?php
//customer_view.php - shows details of a single customer
if ($Feedback == '') {
//data exists, show it
echo '<p>';
echo 'FirstName: <b>' . $FirstName . '</b> ';
echo 'LastName: <b>' . $LastName . '</b> ';
echo 'Email: <b>' . $Email . '</b> ';
echo '<img src="uploads/customer' . $id . '.jpg" />';
if (startSession() && isset($_SESSION["AdminID"])) {
# only admins can see 'peek a boo' link:
echo '<p align="center"><a href="' . VIRTUAL_PATH . 'upload_form.php?' . $_SERVER['QUERY_STRING'] . '">UPLOAD IMAGE</a></p>';
/*
# if you wish to overwrite any of these options on the view page,
# you may uncomment this area, and provide different parameters:
echo '<div align="center"><a href="' . VIRTUAL_PATH . 'upload_form.php?' . $_SERVER['QUERY_STRING'];
echo '&imagePrefix=customer';
echo '&uploadFolder=upload/';
echo '&extension=.jpg';
echo '&createThumb=TRUE';
echo '&thumbWidth=50';
echo '&thumbSuffix=_thumb';
echo '&sizeBytes=100000';
echo '">UPLOAD IMAGE</a></div>';
*/
示例14: foreach
<?php
/**
* Created by PhpStorm.
* User: Zerzolar
* Date: 12.3.2016 г.
* Time: 23:09
*/
require_once 'dbClass.php';
require_once "Sessions.php";
$user = $_POST;
foreach ($user as $key => $val) {
$user[$key] = trim($user[$key]);
$user[$key] = mysqli_real_escape_string($db->link, $user[$key]);
}
$query = "SELECT * FROM `users` WHERE `users`.`username` = '" . $user['username'] . "'";
$result = $db->fetchArray($query);
if (count($result) > 0) {
if ($result[0]['password'] == md5($user['password'])) {
startSession($result[0]['id'], $result[0]['username'], $result[0]['email'], $result[0]['firstname'], $result[0]['lastname'], $result[0]['gender'], $result[0]['birthdate'], $result[0]['joindate'], $result[0]['profilePicId']);
echo $result[0]['profilePicId'];
exit;
}
}
echo "error";
示例15: viewRegister
function viewRegister()
{
$errors = array();
if (!empty($_POST)) {
//vorm esitati
if (empty($_POST["name"])) {
$errors[] = "Nimi puudub.";
}
//nimi olemas
$u = validateInput($_POST["name"]);
$p1 = '';
$p2 = '';
$userMatch = false;
$sql = "SELECT username FROM rsaarmae_users";
$result = mysqli_query($_SESSION['connection'], $sql);
while ($row = mysqli_fetch_assoc($result)) {
if ($row['username'] == $u) {
$userMatch = true;
$errors[] = "Sellise nimega kasutaja on juba registreeritud, proovige teist nime";
}
}
if (empty($_POST["name"])) {
}
if (empty($_POST["password"])) {
$errors[] = "Salasõna puudub.";
} else {
$p1 = validateInput($_POST["password"]);
}
if (empty($_POST["password_check"])) {
$errors[] = "Salasõna kontroll puudub.";
} else {
$p2 = validateInput($_POST["password_check"]);
}
if ($p1 != $p2) {
$errors[] = "Salasõnad ei ühti.";
}
if (!$userMatch && empty($errors)) {
$salt = sha1($p1 . $u . $p1);
//salasõna räsi tekitamine ja soolamine
$query = "INSERT INTO rsaarmae_users (username, pass) VALUES ('{$u}', '{$salt}');";
mysqli_query($_SESSION['connection'], $query);
startSession();
startSession();
$_SESSION["teade"] = "Registreeritud kasutaja nimega '" . $u . "'.";
header("Location: controller.php?mode=index");
exit(0);
}
}
require_once 'register.php';
}