简体   繁体   中英

SSO/Auth between different sub-domains (w/ PHP)?

I was wondering if I could use PHP to do SSO between two different sub-domains. (ex: parappawithfries.com and *.parappawithfries.com). My config is not like it should be, because I use cloudflare to point my subs to a different 000webhost website. I know I should just use infinityfree, but I don't get https:// and subdomains. Lots of issues, but it it could be fixed, that'd be great. ANYWAY, I was wondering if I could do something like this in HTML.

<script src="https://parappawithfries.com/user.js"></script>

and in user.js (in the NON sub-domain) needs to set a cookie with the user's PHPSESSID copied over by JS by basically printing it as a variable. Can I do that with JS, AJAX, jQuery, or any way possible without using anything other than PHP, HTML, JS, AJAX, or jQuery?

Ok, ok lemme edit im sorry. parappawithfries.com points to parappawithfries.000webhostapp.com. It's subdomains don't point to a folder in parappawithfries.000webhostapp.com. it points to a DIFFERENT 000webhost site. Not a folder in parappawithfries.000webhostapp.com.

Oh yeah, btw, here is an example: https://imgur.com/a/giBwTwp

I need to edit... AGAIN (this is getting tiring)

I switched hosting from 000webhost to infinityfree and I got subdomains working. Time to see if it will work now...

In PHP if you setcookie() with a $domain parameter (eg parappawithfries.com), that cookie can be accessed by that domain and any subdomains.

https://secure.php.net/manual/en/function.setcookie.php

From there, you can make sure all your sites are set up to used a singular Memcached server, and they should all be able to share the same session(s).

Have a look at the below link for some details on setting this up.

https://www.digitalocean.com/community/tutorials/how-to-share-php-sessions-on-multiple-memcached-servers-on-ubuntu-14-04

Cookies cannot be shared across different domains; however, you could make use of another domain that would have the cookies and the authentication could take place there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM