Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >无法跨域和子域共享会话

无法跨域和子域共享会话
EN

Stack Overflow用户
提问于 2020-01-20 21:54:56
回答 1查看 281关注 0票数 1

我有一个Laravel应用程序,我希望论坛部分有自己的子域,并允许用户保持登录时,访问主网站。这是我的config/session.php文件。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?php

use Illuminate\Support\Str;

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", "dynamodb", "array"
    |
    */

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

    /*
    |--------------------------------------------------------------------------
    | 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' => env('SESSION_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' => env('SESSION_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", "memcached", or "dynamodb" session drivers you may
    | list a cache store that should be used for these sessions. This value
    | must match with one of the application's configured cache "stores".
    |
    */

    'store' => env('SESSION_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' => env(
        'SESSION_COOKIE',
        Str::slug(env('APP_NAME', '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' => '.intransportal.test',

    /*
    |--------------------------------------------------------------------------
    | 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,

    /*
    |--------------------------------------------------------------------------
    | Same-Site Cookies
    |--------------------------------------------------------------------------
    |
    | This option determines how your cookies behave when cross-site requests
    | take place, and can be used to mitigate CSRF attacks. By default, we
    | do not enable this as other CSRF protection services are in place.
    |
    | Supported: "lax", "strict"
    |
    */

    'same_site' => null,

];

我用点作为域名的前缀,如上所述。我也运行了php artisan session:table并清除了cookies和缓存,但当我访问我的子域时,我仍然没有登录。我遗漏了哪些步骤?

顺便说一下,论坛和主站点在同一个Laravel项目中。

EN

回答 1

Stack Overflow用户

发布于 2020-01-21 19:22:48

我想通了,伙计们

当我在.env中更改会话驱动程序时,我在Chrome的隐身模式下对其进行了测试

我使用普通模式和跨域加载会话对其进行了测试。

基本上,由于cookie不能跨域共享,您必须使用数据库驱动程序。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59831391

复制
相关文章
Ajax跨子域
主页index.html的主要代码如下: <button onclick="crossDomain();">开始跨域</button> <div id="ajax"></div> <iframe src="http://work.2fool.cn/crossdomain/iframe.html" id="iframe" style="display:none;"> </iframe> <script type="text/javascript"> document.domain = '2fool.cn';
磊哥
2018/04/26
1.2K0
跨域共享CORS详解及Gin配置跨域
跨域简介 当两个域具有相同的协议(如http), 相同的端口(如80),相同的host,那么我们就可以认为它们是相同的域(协议,域名,端口都必须相同)。 跨域就指着协议,域名,端口不一致,出于安全考虑,跨域的资源之间是无法交互的(例如一般情况跨域的JavaScript无法交互,当然有很多解决跨域的方案) 解决跨域几种方案 /* CORS 普通跨域请求:只服务端设置Access-Control-Allow-Origin即可, 前端无须设置,若要带cookie请求:前后端都需要设置。
iginkgo18
2020/12/01
1.8K0
跨域资源共享
CORS全称为Cross-Origin Resource Sharing,被译为跨域资源共享,新増了一组HTTP首部字段,允许服务器声明哪些源站有权限访问哪些资源。
Dreamy.TZK
2020/08/12
8180
nginx配置跨域访问,无法生效_页面跨域访问
由于浏览器同源策略的存在使得一个源中加载来自其它源中资源的行为受到了限制。即会出现跨域请求禁止。
全栈程序员站长
2022/11/10
7.7K0
跨域资源共享(CORS)
简单先了解一下CORS,方便我们后续去挖一些CORS的漏洞,最近CORS也是比较火的!
黑伞安全
2019/10/16
3.6K0
【thinkphp】跨域共享cookies session
本文链接:【thinkphp】跨域共享cookies session - http://www.96php.cn/post-63.html
96php.cn
2018/08/20
1.9K0
【thinkphp】跨域共享cookies session
理解跨域资源共享
CORS 或跨域资源共享是一种 http 机制,它允许用户通过使用一些额外的头来访问别的域的资源。例如,假设位于http://test1.domain.com上的应用程序需要对位于 http://test2.domain.com/some/awesome/endpoint上的 api 进行 REST 调用。
madneal
2019/11/28
1.1K0
同源和跨域详解_如何实现跨域
举例来说,这个网址http://www.example.com/dir/page.html协议是http://,
全栈程序员站长
2022/09/20
1K0
Cors跨域(二):实现跨域Cookie共享的三要素
上篇文章(Cors跨域(一):深入理解跨域请求概念及其根因)用超万字的篇幅把Cors几乎所有概念都扫盲了,接下来将逐步提出解决方案等实战性问题以及查漏补缺。
YourBatman
2021/06/24
8.8K0
assetfinder – 查找相关域和子域
assetfinder 是一种基于 Go 的工具,用于从各种来源(包括 Facebook、ThreatCrowd、Virustotal 等)中查找可能与给定域相关的相关域和子域。
Khan安全团队
2021/12/30
1.1K0
跨域资源共享的使用
本文主要介绍了跨域资源共享(CORS)的相关知识,包括CORS的工作原理、服务器端如何配置支持CORS、如何发起跨域请求以及如何处理响应等。此外,还提供了关于浏览器对CORS请求的处理流程和可能遇到的错误情况的说明。
IMWeb前端团队
2017/12/29
1.5K0
跨域资源共享的使用
跨域与跨域访问
什么是跨域 跨域是指从一个域名的网页去请求另一个域名的资源。比如从www.baidu.com 页面去请求 www.google.com 的资源。跨域的严格一点的定义是:只要 协议,域名,端口有任何一个的不同,就被当作是跨域 为什么浏览器要限制跨域访问呢? 原因就是安全问题:如果一个网页可以随意地访问另外一个网站的资源,那么就有可能在客户完全不知情的情况下出现安全问题。比如下面的操作就有安全问题: 用户访问www.mybank.com ,登陆并进行网银操作,这时cookie啥的都生成并存放在浏览器 用户突然想
MonroeCode
2018/02/09
5.3K0
再战子域共享Cookie问题
昨天贾宁旨光临寒舍,吃过晚饭回来后就跟他聊天,后来又玩了一会儿《Black Hawk Down》对战,到了大概晚上11点多,开始继续尝试用 Response.Cookies.Domain 来解决子域共享 Cookie 的问题。 根据网上的资料,包括 MSDN 的文章都说设置 Response.Cookies("domain").Domain = "Microsoft.com" 这样的形式以后,可以实现该Cookie对整个“Microsoft.com”域下的所有服务器都可以共享。我在本机测试的时候,也的确实现
小李刀刀
2018/03/02
1.5K0
跨域资源共享CORS漏洞
跨域资源共享(CORS)是一种放宽同源策略的机制,它允许浏览器向跨源服务器,发出 XMLHttpRequest 请求,从而克服了 AJAX 只能同源使用的限制,以使不同的网站可以跨域获取数据,目前已经被绝大多数浏览器支持,并被主流网站广泛部署使用。跨域资源共享 CORS 漏洞主要是由于程序员配置不当,对于 Origin 源校验不严格,从而造成跨域问题,攻击者可以利用 CORS 错误配置漏洞,从恶意网站跨域读取受害网站的敏感信息。
LuckySec
2022/11/02
4K0
跨域资源共享CORS漏洞
跨域资源共享的使用
页面中常常会有需要跨域通信的需求实现,我们知道浏览器的同源策略是不允许不同域之间的相互通信的(这里不深究域的定义及如何才算跨域),比如a.com有b.com想要的数据,那么在b.com页面中发送ajax请求到a.com是不允许的,相信大家都知道一些跨域通信的实现方法:
IMWeb前端团队
2019/12/04
1.1K0
跨域资源共享的使用
跨域资源共享 CORS 详解
CORS是一个W3C标准,全称是"跨域资源共享"(Cross-origin resource sharing)。 它允许浏览器向跨源服务器,发出XMLHttpRequest请求,从而克服了AJAX只能
ruanyf
2018/04/12
1.1K0
跨域资源共享 CORS 详解
跨域与跨域访问_如何实现跨域访问
跨域是指从一个域名的网页去请求另一个域名的资源。比如从www.baidu.com 页面去请求 www.google.com 的资源。跨域的严格一点的定义是:只要 协议,域名,端口有任何一个的不同,就被当作是跨域
全栈程序员站长
2022/11/10
5.5K0
跨域和CORS
  同源策略(Same origin policy)是一种约定,它是浏览器最核心也最基本的安全功能,如果缺少了同源策略,则浏览器的正常功能可能都会受到影响。可以说Web是构建在同源策略基础之上的,浏览器只是针对同源策略的一种实现。    
changxin7
2019/12/19
1.1K0
Django跨域(前端跨域)
其实AJAX就是在Javascript中多添加了一个对象:XMLHttpRequest对象。所有的异步交互都是使用XMLHttpServlet对象完成的。也就是说,我们只需要学习一个Javascript的新对象即可。
全栈程序员站长
2022/07/21
7.9K0
Django跨域(前端跨域)
PHP 禁止跨域 - 限制跨域 - 不限制跨域详解
先来了解一下什么是跨域: 1.什么是跨域?跨域:指的是浏览器不能执行其他网站的脚本。它是由浏览器的同源策略造成的,是浏览器对javascript施加的安全限制。例如:a页面想获取b页面资源,如果a、b页面的协议、域名、端口、子域名不同,所进行的访问行动都是跨域的,而浏览器为了安全问题一般都限制了跨域访问,也就是不允许跨域请求资源。注意:跨域限制访问,其实是浏览器的限制。理解这一点很重要!!!同源策略:是指协议,域名,端口都要相同,其中有一个不同都会产生跨域;
axiomxs
2021/11/26
2.6K0

相似问题

跨域(主域和子域)共享PHP会话

21

跨多个域的子域共享会话

13

跨子域共享快捷会话

11

跨域和子域共享cookies

10

rails 4跨子域共享会话

12
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文