2017-08-15 153 views
1

我在Windows機器上開發了一個laravel應用程序,項目在那裏工作得很好。該項目與Dropbox同步,當我移動到Mac時,我的laravel項目不在macos上工作。
我面臨的問題是它重新生成每個頁面上的會話ID重新加載。我使用數據庫作爲會話存儲,並在數據庫中添加一個新條目。
我曾嘗試使用文件驅動程序作爲會話存儲,併發生同樣的事情,它會在存儲/框架/會話中創建一個新文件,證明文件權限可以正常寫入。
我所有的形式已經停止工作並獲得會話在每頁重新加載

TokenMismatchException in VerifyCsrfToken.php 

權限存儲文件夾和會話文件夾的是755

enter image description here

每個重載的應用程序添加一個數據庫中的新條目如我我正在使用數據庫驅動程序來保存會話

enter image description here

下面是正如我提到的相同的項目我的Windows機器上運行的很好,沒有工作在我的MacOS由於會話問題我的會議文件

<?php 
return [ 

    /* 
    |-------------------------------------------------------------------------- 
    | Default Session Driver 
    |-------------------------------------------------------------------------- 
    | 
    | This option controls the default session "driver" that will be used on 
    | requests. By default, we will use the lightweight native driver but 
    | you may specify any of the other wonderful drivers provided here. 
    | 
    | Supported: "file", "cookie", "database", "apc", 
    |   "memcached", "redis", "array" 
    | 
    */ 

    'driver' => env('SESSION_DRIVER', 'file'), 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Lifetime 
    |-------------------------------------------------------------------------- 
    | 
    | Here you may specify the number of minutes that you wish the session 
    | to be allowed to remain idle before it expires. If you want them 
    | to immediately expire on the browser closing, set that option. 
    | 
    */ 

    'lifetime' => 120, 

    'expire_on_close' => false, 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Encryption 
    |-------------------------------------------------------------------------- 
    | 
    | This option allows you to easily specify that all of your session data 
    | should be encrypted before it is stored. All encryption will be run 
    | automatically by Laravel and you can use the Session like normal. 
    | 
    */ 

    'encrypt' => false, 

    /* 
    |-------------------------------------------------------------------------- 
    | Session File Location 
    |-------------------------------------------------------------------------- 
    | 
    | When using the native session driver, we need a location where session 
    | files may be stored. A default has been set for you but a different 
    | location may be specified. This is only needed for file sessions. 
    | 
    */ 

    'files' => storage_path('framework/sessions'), 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Database Connection 
    |-------------------------------------------------------------------------- 
    | 
    | When using the "database" or "redis" session drivers, you may specify a 
    | connection that should be used to manage these sessions. This should 
    | correspond to a connection in your database configuration options. 
    | 
    */ 

    'connection' => null, 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Database Table 
    |-------------------------------------------------------------------------- 
    | 
    | When using the "database" session driver, you may specify the table we 
    | should use to manage the sessions. Of course, a sensible default is 
    | provided for you; however, you are free to change this as needed. 
    | 
    */ 

    'table' => 'sessions', 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Cache Store 
    |-------------------------------------------------------------------------- 
    | 
    | When using the "apc" or "memcached" session drivers, you may specify a 
    | cache store that should be used for these sessions. This value must 
    | correspond with one of the application's configured cache stores. 
    | 
    */ 

    'store' => null, 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Sweeping Lottery 
    |-------------------------------------------------------------------------- 
    | 
    | Some session drivers must manually sweep their storage location to get 
    | rid of old sessions from storage. Here are the chances that it will 
    | happen on a given request. By default, the odds are 2 out of 100. 
    | 
    */ 

    'lottery' => [2, 100], 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Cookie Name 
    |-------------------------------------------------------------------------- 
    | 
    | Here you may change the name of the cookie used to identify a session 
    | instance by ID. The name specified here will get used every time a 
    | new session cookie is created by the framework for every driver. 
    | 
    */ 

    'cookie' => 'laravel_session', 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Cookie Path 
    |-------------------------------------------------------------------------- 
    | 
    | The session cookie path determines the path for which the cookie will 
    | be regarded as available. Typically, this will be the root path of 
    | your application but you are free to change this when necessary. 
    | 
    */ 

    'path' => '/', 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Cookie Domain 
    |-------------------------------------------------------------------------- 
    | 
    | Here you may change the domain of the cookie used to identify a session 
    | in your application. This will determine which domains the cookie is 
    | available to in your application. A sensible default has been set. 
    | 
    */ 

    'domain' => env('SESSION_DOMAIN', null), 

    /* 
    |-------------------------------------------------------------------------- 
    | HTTPS Only Cookies 
    |-------------------------------------------------------------------------- 
    | 
    | By setting this option to true, session cookies will only be sent back 
    | to the server if the browser has a HTTPS connection. This will keep 
    | the cookie from being sent to you if it can not be done securely. 
    | 
    */ 

    'secure' => env('SESSION_SECURE_COOKIE', false), 

    /* 
    |-------------------------------------------------------------------------- 
    | HTTP Access Only 
    |-------------------------------------------------------------------------- 
    | 
    | Setting this value to true will prevent JavaScript from accessing the 
    | value of the cookie and the cookie will only be accessible through 
    | the HTTP protocol. You are free to modify this option if needed. 
    | 
    */ 

    'http_only' => true, 

]; 

。我在網上嘗試了很多解決方案,但沒有爲我工作。

+1

請給你的配置 – MisaGH

+0

我加入了更多細節的詳細信息。 –

+0

什麼是您的SESSION_DOMAIN env文件? – MisaGH

回答

1

這對我來說就像在本地主機上使用cookie作爲域時的一個長期問題的變體。總之,你不能這樣做,因爲在許多瀏覽器中,域名需要2'。'至少在域名中的字符。

這些都ok:

www.domain.com 
.domain.com 

這個問題在不同的地方進行了討論,特別是到PHP(這Laravel是受惠於)手動和set cookie,特別是對「一節的意見中域「:

該cookie可用於的(子)域。將此設置爲 子域(如「www.example.com」)將使該Cookie可用 到該子域及其所有其他子域(即 w2.www.example.com)。要使Cookie可用於整個域 (包括其所有子域),只需將該值設置爲域名 名稱(在本例中爲'example.com')。

舊版瀏覽器仍在實施已棄用的»RFC 2109可能需要 。以匹配所有子域。

解決這個問題的一個簡單方法是在/ etc/hosts文件中爲您選擇的域放置一個別名。根據rfc2606,最佳選擇是在TLD上使用.test。

// /etc/hosts 
127.0.0.1 localhost www.yourbogusdomain.test 

就像旁白一樣,這樣的原因是爲什麼我使用Vagrant/virtualbox/docker。您可能要在Linux服務器上託管,所以爲什麼要在Windows/Mac OS上開發,使用一堆解決方法,以及WAMP/MAMP /無論什麼堵塞您的計算機的服務,您將不得不啓動/停止所有時間,更不用說安裝/升級了?

最後但並非最不重要的一點,它提供的虛擬化和網絡選項允許您設置集羣並測試高級多主機配置,這些配置在最好的情況下會嘗試在工作站上配置爲一系列相互關聯的進程。

相關問題