Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于跨域请求,验证码无效的一些问题 #24

Open
ghost opened this issue May 8, 2018 · 3 comments
Open

关于跨域请求,验证码无效的一些问题 #24

ghost opened this issue May 8, 2018 · 3 comments

Comments

@ghost
Copy link

ghost commented May 8, 2018

假如我有两个站点,分别是www.aaa.com和api.bbb.com,我的bbb.com站点提供了注册接口,当a站点想要发送注册请求时,会带上b站点给它提供的验证码(http://api.bbb.com/verifycode.html)。因为我们的验证码是使用session进行存储,我看到,咱们会生成一个sessionid。收到浏览器同源问题的限制,当a站点通过ajax请求注册时,并不会带上sessionid。所以会导致验证码失效,无法通过请求。
我不知道自己是否表达清楚,我觉得应该考虑到这样的问题,或者我们可以增加一个配置选项,可以让用户自由选择使用何种方式缓存验证码!

@genffy
Copy link

genffy commented Oct 15, 2018

repost,我也是遇到了这个问题,无奈将登陆放在原来的地方了。。。。

@xbyter
Copy link

xbyter commented Dec 26, 2018

建议新增依赖注入支持, 我是直接Copy份库再改进为可以使用缓存存储

@iDivines
Copy link

iDivines commented Jun 26, 2019

public function check($code, $id = ''){
    $key = $this->authcode($this->seKey) . $id;
    // 验证码不能为空
    $secode = Session::get($key, '');
    if (empty($code) || empty($secode)) {
        return false;
    }
    // session 过期
    if (time() - $secode['verify_time'] > $this->expire) {
        Session::delete($key, '');
        return false;
    }

    if ($this->authcode(strtoupper($code)) == $secode['verify_code']) {
        $this->reset && Session::delete($key, '');
        return true;
    }

    return false;
}

看了源码,验证码是保存在session中的,如果跨域没办法验证的,只能把存储的代码改下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants