本文整理汇总了PHP中Session函数的典型用法代码示例。如果您正苦于以下问题:PHP Session函数的具体用法?PHP Session怎么用?PHP Session使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Session函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: thumbnail2
public function thumbnail2(Request $request)
{
if ($request->hasFile('thumbnail_file2')) {
$messages = ['photo.image' => '上传文件必须是图片', 'photo.max' => '上传文件不能大于:maxkb'];
$this->validate($request, ['photo' => 'image|max:100000'], $messages);
if ($request->file('thumbnail_file2')->isValid()) {
$OriginalName = $request->file('thumbnail_file2')->getClientOriginalName();
$file_pre = sha1(time() . $OriginalName);
//取得当前时间戳
$file_suffix = substr(strchr($request->file('thumbnail_file2')->getMimeType(), "/"), 1);
//取得文件后缀
$destinationPath = 'uploads';
//上传路径
$fileName = $file_pre . '.' . $file_suffix;
//上传文件名
Image::make($request->file('thumbnail_file2'))->resize(300, null, function ($constraint) {
$constraint->aspectRatio();
})->save('uploads/thumbnails/' . $fileName);
$request->file('thumbnail_file2')->move($destinationPath, $fileName);
$img = new Img();
$img->name = $fileName;
$img->save();
Session()->flash('img2', $fileName);
return $fileName;
} else {
return "上传文件无效!";
}
} else {
return "文件上传失败!";
}
}
示例2: run
/**
* @param integer $v
* @return bool
*/
public function run($v)
{
$gmt = (int) $v;
$gmt = $gmt < -14 || $gmt > 12 ? 0 : $gmt;
Session()->set('timezone', $gmt);
return true;
}
示例3: delete
public function delete($id)
{
$song = Song::find($id);
$song->delete();
Session()->flash('deletesong', 'Song is Deleted');
return Redirect::to('song');
}
示例4: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
$route_uri = $request->route()->getName();
$route = strstr($route_uri, '.', true);
if (Auth::check()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
$permission = UserHelper::get_route_permission($route);
if ($route_uri == $route . '.index' && isset($permission->list) && $permission->list == 1) {
return $next($request);
} elseif ($route_uri == $route . '.show' && isset($permission->view) && $permission->view == 1) {
return $next($request);
} elseif ($route_uri == $route . '.create' && isset($permission->add) && $permission->add == 1) {
return $next($request);
} elseif ($route_uri == $route . '.store' && isset($permission->add) && $permission->add == 1) {
return $next($request);
} elseif ($route_uri == $route . '.edit' && isset($permission->edit) && $permission->edit == 1) {
return $next($request);
} elseif ($route_uri == $route . '.update' && isset($permission->edit) && $permission->edit == 1) {
return $next($request);
} else {
Session()->flash('warning_message', 'You do not have permission to access!');
if (isset($permission->list) && $permission->list == 1) {
return redirect($route);
} else {
return redirect('/home');
}
}
}
} else {
return redirect()->guest('login');
}
}
示例5: getCurrUser
/**
* 判断是否登录及获取当前管理员信息
*/
protected function getCurrUser()
{
$currUser = Session("system_curr_user");
if (empty($currUser)) {
return;
}
$currUser = unserialize(authcode($currUser));
if (!isset($currUser['id'])) {
return;
}
$user = D("SysUser")->selectOne($currUser['id']);
if (!$user) {
return;
}
if (!$user['status']) {
return;
}
// 帐号禁用
$this->isLogined = true;
unset($user['password']);
$user['auth'] = unserialize($user['auth']);
$user['upTime'] = $currUser['lastTime'];
$user['upIp'] = $currUser['lastIp'];
$this->currUser = $user;
}
示例6: logout
public function logout()
{
Auth::logout();
Session()->forget('shopping');
Session()->forget('nbrProduct');
return redirect('/')->with(['messageLogout' => trans('app.logoutSuccess'), 'alert' => 'success']);
}
示例7: GetID
function GetID($type)
{
$option = Session($type);
if ($option == "") {
$option = Cookie($type);
}
return $option;
}
示例8: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!auth()->user()->hasRole('administrator')) {
Session()->flash('flash_message_warning', 'Only Allowed for admins');
return redirect()->back();
}
return $next($request);
}
示例9: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!auth()->user()->can('lead-create')) {
Session()->flash('flash_message_warning', 'Not allowed to create lead');
return redirect()->route('leads.index');
}
return $next($request);
}
示例10: _initialize
public function _initialize()
{
//用来检查当前用户的合法性
$type = Session('type');
if ($type != 2) {
$this->redirect('Home/Login/index');
}
}
示例11: getDelete
public function getDelete($id)
{
$sb1 = Sambutan::find($id);
File::delete('resources/assets/img/sambutan/' . $sb1->foto);
Sambutan::where('id', $id)->delete();
\Session()->flash('success', 'Berhasil mengosongkan data');
return redirect(route('sambutan'));
}
示例12: store
public function store(Request $request)
{
$request->parent_id = empty($request->parent_id) ? 1 : $request->parent_id;
$messages = ['name.required' => '分类名不能为空'];
$this->validate($request, ['name' => 'required'], $messages);
Category::create(['name' => $request->name, 'parent_id' => $request->parent_id]);
Session()->flash('status', 'category create was successful!');
return redirect('/admin/categorys/');
}
示例13: store
public function store(Request $request)
{
$token = Session('_token');
$product_id = $request->get('product_id');
$quantity = $request->get('quantity');
$price = Product::find($product_id)->price;
Cart::create(['product_id' => $product_id, 'quantity' => $quantity, '_token' => $token, 'price' => $price]);
return redirect('cart')->with(['message' => 'Le produit a été ajouté dans votre panier']);
}
示例14: destroy
public function destroy($id)
{
try {
$client = Client::findorFail($id);
$client->delete();
Session()->flash('flash_message', 'Client successfully deleted');
} catch (\Illuminate\Database\QueryException $e) {
Session()->flash('flash_message_warning', 'Client can NOT have, leads, or tasks assigned when deleted');
}
}
示例15: showCode
function showCode()
{
$code = Post('code');
$check = Session('check_num');
if ($code == $check) {
echo '0';
} else {
echo '1';
}
}