Same URL without www different session

2019-07-31 15:09发布

I have the following issue (that i know many of you probably have or had) but still i haven't found an explanation anywhere that satisfies me, or at least a proper solution.

In the session script of any of the sites that i make, if the user goes through the domain using www.domain.com and logs in, but then in a different tab he goes to the same page without the www. (domain.com) The session hasn't been started in that one.

i have found this two questions on stackoverflow but none of them offers a real solution or at least an explanation of why this behavior.

different session with url's with-www and without-www

PHP session login different for url with www and without www?

Ok to go the point, This redirections and rules doesn't work in my case.

Why? because i'm working with a payment provider that uses cURL to retrieve some data i send to them, and when they send the response back to me, they use a default URL wich i have to give to them. currently they set up the address as www. but what if one of my users goes to an especific page of the site using the domain without the www.? When i get the response from the provider it goes to www.site.com and the user there is not logged. and no actions can be applied.

Any help in this please?

Thanks Cheers.

1条回答
狗以群分
2楼-- · 2019-07-31 15:55

As said there http://www.php.net/manual/en/function.setcookie.php

Cookies available to a lower domain, such as 'example.com' will be available to higher subdomains, such as 'www.example.com'

So just do

session_set_cookie_params(0, '/', 'yourdomain.com');

without www

查看更多
登录 后发表回答