php - Session resets on every page reload -
i developing laravel application on windows machine , project working fine there. project synced dropbox , when moved mac laravel project not working here on macos.
issue facing regenerates session id on each page reload. using database session storage , adds new entry in database.
have tried using file driver session storage , same thing happens creates new file in storage/framework/session justifies file permissions ok , writeable.
of forms have stopped working , getting
tokenmismatchexception in verifycsrftoken.php
permission of storage folder , session folder 755
each reload on application adds new entry in db using database driver save session
below session file
<?php return [ /* |-------------------------------------------------------------------------- | default session driver |-------------------------------------------------------------------------- | | option controls default session "driver" used on | requests. default, use lightweight native driver | may specify of other wonderful drivers provided here. | | supported: "file", "cookie", "database", "apc", | "memcached", "redis", "array" | */ 'driver' => env('session_driver', 'file'), /* |-------------------------------------------------------------------------- | session lifetime |-------------------------------------------------------------------------- | | here may specify number of minutes wish session | allowed remain idle before expires. if want them | expire on browser closing, set option. | */ 'lifetime' => 120, 'expire_on_close' => false, /* |-------------------------------------------------------------------------- | session encryption |-------------------------------------------------------------------------- | | option allows specify of session data | should encrypted before stored. encryption run | automatically laravel , can use session normal. | */ 'encrypt' => false, /* |-------------------------------------------------------------------------- | session file location |-------------------------------------------------------------------------- | | when using native session driver, need location session | files may stored. default has been set different | location may specified. needed file sessions. | */ 'files' => storage_path('framework/sessions'), /* |-------------------------------------------------------------------------- | session database connection |-------------------------------------------------------------------------- | | when using "database" or "redis" session drivers, may specify | connection should used manage these sessions. should | correspond connection in database configuration options. | */ 'connection' => null, /* |-------------------------------------------------------------------------- | session database table |-------------------------------------------------------------------------- | | when using "database" session driver, may specify table | should use manage sessions. of course, sensible default | provided you; however, free change needed. | */ 'table' => 'sessions', /* |-------------------------------------------------------------------------- | session cache store |-------------------------------------------------------------------------- | | when using "apc" or "memcached" session drivers, may specify | cache store should used these sessions. value must | correspond 1 of application's configured cache stores. | */ 'store' => null, /* |-------------------------------------------------------------------------- | session sweeping lottery |-------------------------------------------------------------------------- | | session drivers must manually sweep storage location | rid of old sessions storage. here chances | happen on given request. default, odds 2 out of 100. | */ 'lottery' => [2, 100], /* |-------------------------------------------------------------------------- | session cookie name |-------------------------------------------------------------------------- | | here may change name of cookie used identify session | instance id. name specified here used every time | new session cookie created framework every driver. | */ 'cookie' => 'laravel_session', /* |-------------------------------------------------------------------------- | session cookie path |-------------------------------------------------------------------------- | | session cookie path determines path cookie | regarded available. typically, root path of | application free change when necessary. | */ 'path' => '/', /* |-------------------------------------------------------------------------- | session cookie domain |-------------------------------------------------------------------------- | | here may change domain of cookie used identify session | in application. determine domains cookie | available in application. sensible default has been set. | */ 'domain' => env('session_domain', null), /* |-------------------------------------------------------------------------- | https cookies |-------------------------------------------------------------------------- | | setting option true, session cookies sent | server if browser has https connection. keep | cookie being sent if can not done securely. | */ 'secure' => env('session_secure_cookie', false), /* |-------------------------------------------------------------------------- | http access |-------------------------------------------------------------------------- | | setting value true prevent javascript accessing | value of cookie , cookie accessible through | http protocol. free modify option if needed. | */ 'http_only' => true, ];
as mentioned same project running fine on windows machine , not working on macos due session issue. tried many solutions online nothing worked me.
this looks me variation of long time issue when using cookies localhost domain. in short, can't it, because in many browsers domain name requires 2 '.' characters in domain name @ minimum.
these ok:
www.domain.com .domain.com
this issue has been discussed in various places, , in particular php (which laravel beholden to) in manual , comments set cookie , in particular section on 'domain':
the (sub)domain cookie available to. setting subdomain (such 'www.example.com') make cookie available subdomain , other sub-domains of (i.e. w2.www.example.com). make cookie available whole domain (including subdomains of it), set value domain name ('example.com', in case).
older browsers still implementing deprecated » rfc 2109 may require leading . match subdomains.
a simple way around this, put alias in /etc/hosts file domain of choosing. best option, according rfc2606 use .test @ tld.
// /etc/hosts 127.0.0.1 localhost www.yourbogusdomain.test
just aside, reasons why use vagrant/virtualbox/docker. going hosted on linux server, why develop on windows/mac os, using bunch of workarounds, along wamp/mamp/whatever clogging machine services have start/stop time, not mention install/upgrade?
last not least, virtualization , networking options provides allow setup clusters , test out advanced multi-host configurations messy @ best try , configure on workstation series of interconnected processes.
Comments
Post a Comment