<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] # Session ## 簡介 ### 配置 Session 配置文件`config/session.php`,默認使用`file`驅動。生產環境中,建議使用`memcached`或`redis`驅動。Session`driver`的配置預設可選驅動: * `file`- 將 Session 存儲在`storage/framework/sessions`中。 * `cookie`- Sessions 被存儲在安全加密的 cookie 中。 * `database`- Sessions 被存儲在關系型數據庫中。 * `memcached`/`redis`- Sessions 被存儲在基于高速緩存的存儲系統中。 * `array`- Sessions 存儲在 PHP 數組中,但不會被持久化。 > 提示:數組驅動一般用于[測試]并且防止存儲在 Session 中的數據被持久化。 ### 驅動程序先決條件 #### 數據庫驅動 ``` php artisan session:table php artisan migrate // .env 或者 config/session.php 設置 SESSION_DRIVER=database ``` #### Redis驅動 ``` $ composer require predis/predis // .env 或者 config/session.php 設置 SESSION_DRIVER=redis // redis 配置文件 config/database.php ``` ## 使用 Session ### 使用 Request 實例 ``` // 獲取數據 $value = $request->session()->get('key'); // 設置默認值 $value = $request->session()->get('key', 'default'); // 閉包默認值 $value = $request->session()->get('key', function () { return 'default'; }); // 獲取所有的 Session 數據, $data = $request->session()->all(); // 獲取并刪除 $value = $request->session()->pull('key', 'default'); // 判斷 Session 中是否存在某個值 if ($request->session()->has('users')) { // 存在且不為 null } if ($request->session()->exists('users')) { // 存在,允許值為 null } // 存儲數據 $request->session()->put('key', 'value'); // 在 Session 數組中保存數據 $request->session()->push('user.teams', 'developers'); // 刪除指定 session $request->session()->forget('key'); // 刪除所有 session $request->session()->flush(); ``` ### 使用輔助函數 ``` // 獲取 session 中的一條數據... $value = session('key'); // 指定一個默認值... $value = session('key', 'default'); // 在 Session 中存儲一條數據... session(['key' => 'value']); ``` ### 閃存數據 在 Session 中保存數據用于下一次請求,可以使用`flash`方法。使用這個方法保存在 Session 中的數據,只會保留到下一個 HTTP 請求到來之前,然后就會被刪除。閃存數據主要用于短期的狀態消息: ``` // 在 Session 中保存數據用于下一次請求 $request->session()->flash('status', 'Task was successful!'); // 所有一次性請求再次保留到下一次請求 $request->session()->reflash(); // 保存一次性數據 $request->session()->keep(['username', 'email']); ``` ### 重新生成 Session ID 重新生成 session ID 通常是為了防止惡意用戶利用[session fixation](https://en.wikipedia.org/wiki/Session_fixation)對你的應用進行攻擊。 如果你使用了內置函數`LoginController`,Laravel 會自動重新生成身份認證中的 Session ID。否則,你需要手動使用`regenerate`方法重新生成 Session ID。 ``` $request->session()->regenerate(); ``` ## 請求數據使用 Session ### 將輸入數據傳送到 Session ``` // 將輸入數據傳送到 Session,等待后續操作使用 $request->flash(); $request->flashOnly(['username', 'email']); // 只保留 username、email $request->flashExcept('password'); // 排除 password ``` ### 傳送數據至 session 并跳轉 ``` return redirect('form')->withInput(); return redirect('form')->withInput( $request->except('password') ); ``` ### 獲取舊數據 ``` $username = $request->old('username'); // Blade模板顯示舊數據 <input type="text" name="username" value="{{ old('username') }}"> ``` ## 跳轉使用 Session ### 帶有傳送 Session 值的跳轉 ``` Route::post('user/profile', function () { // Update the user's profile... return redirect('dashboard')->with('status', 'Profile updated!'); }); // 跳轉后前臺顯示 @if (session('status')) <div class="alert alert-success"> {{ session('status') }} </div> @endif ``` ## 添加自定義 Session 驅動 [參考文檔](https://learnku.com/docs/laravel/5.8/session/3898#db7cdb)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看