User Authentication Across Subdomains on Localhost - php

I'm building an app on my localhost. When I login via one subdomain, (e.g. sub.localhost/) I need to access that logged-in user with Auth:: in all other subdomains of my application (e.g. sub2.localhost/, sub3.localhost/).
I made the change as this post suggests in config/session.php:
'domain' => '.localhost/',
No beans. In fact now I can't log in at all. Does this only work with a non-localhost domain? That would suck.

Did you try with only .localhost instead of .localhost/
if it is still doesn't work you can create an other host pointing to 127.0.0.1 : edit the /etc/hosts or Windows\System32\drivers\etc\hosts to set an other hostname for example : 127.0.0.1 host.loc

Related

Laravel session - don't want to share domain and sub domain session

I've 1 domain and created 1 sub domain from main domian says www.example.com and dev.example.com. www.example.com is production domain and dev.example.com is development environment.
I've then clone 2 projects from a same repo but put them in different folder. In www.example.com folder .env file, i've set the domain session to example.com. It means in browser when i access from www.example.com or example.com it will be able to share the domain. In dev.example.com, the session_domain i've set is dev.example.com.
Now the problem i've faced is, when i visit www.example.com it will generates a laravel_session domain name of .example.com. with the dot infront it seems like it can be share to sub domain. When i visit to dev.example.com and login with facebook, it seems like it will looks for the .example.com domain session instead of the session created in dev.example.com.
if i delete the laravel_session in www.example.com im able to login with facebook in my dev.example.com or i clear all the cookies/sessions and i'm also able to login with facebook in my dev.example.com.
What i need to do to not make it share the session in sub domian ? And if i put not to share, can the domain be shared when user key in example.com and www.example.com in their browser?
And when it hit invalidstateException when login with facebook, it can be solved by clear all cookie/session. But i think it's not right to ask user to clear cookie browser by themselves. Is there any solution for this?
You just need to use a differently named session cookie in dev.example.com.
if ( $_SERVER['HTTP_HOST'] === 'dev.example.com' )
{
//The default session name is PHPSESSID,
//so if we use a different one, they don't collide.
session_name('DEVSESSIONID');
}
session_start();

Redirect domain to a directory on another domain

I have bought a domain and I want to redirect it to a directory on another subdomain.
Exemple:
A user type www.firstweb.com in the URL bar and he has to be redirected to www.secondweb.com/directory/ but the URL shown has to be www.firstweb.com without iframe.
Other exemple:
www.firstweb.com/contact/ shows the content of www.secondweb.com/directory/contact.php but the URL shown has to be www.firstweb.com/contact/ even after the redirect.
Both domain and servers are hosted by the same company (OVH).
I don't know if it is understandable but I dont know how to figure it out.
Thanks a lot for your help.
J.ROX
You can do this by installing NGINX (http://nginx.org/) on the webserver. Then you can check from which base URL the user is coming from, and return the appropriate content. This is also possible with an Apache server using Virtual Domain Names.
Or you can setup your DNS correctly, this can be done by your domain provider.

Cakephp 2.x parked domain https not working

I have a domain where my code is hosted, and two other domains parked over that domain.
So my code is hosted at domain.com and when I go to domain2.com or domain3.com, the contents of the sites show whatever is hosted at domain.com. The content delivered is based on the url being accessed, so domain2.com would show something different than domain3.com, as I get the url by setting $domain = $_SERVER['HTTP_HOST'];
This works just fine for the http versions of the website, but when I try to access any https versions, it gives a cake error:
URL rewriting is not properly configured on your server. 1) Help me configure it 2) I don't / can't use URL rewriting
That happens on all 3 domains. That page also doesn't have any styling. Cake also can't connect to my database:
Database connection "SQLSTATE[HY000] [1129] Host 'xxx-xx-xxx-x.unifiedlayer.com' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'" is missing, or could not be created.
I've tried looking for that text inside my app folder, to see if I could at least change the contents of that error page, but if I change the text, it doesn't change it in the error page. I've also tried changing all htaccess files, even deleting their content, but that only affects the http versions, and not the https.
I'm starting to think that the https pages are trying to access a different domain that I have, but I don't see how that would be possible.
All 3 domains have ssl certificates and they were all working correctly before I parked the domains.
Any help is much appreciated. I can also provide more details on this issue.
You should do exactly what the mysql error says. Flush the hosts from the main database server. Check you have whitelisted your websites on a firewall/iptables.

domain mapping: php or nodejs & nginx

I want to automate a process so that my clients can sign up on their own to my application, insert them own domain name and i can map the domain name to their subdomain.
For example, they have a subdomain called mappable.example.com and they have a domain name called mappable.com
I have two questions:
1. How do you create a subdomain for them in php and/or nodejs called mappable.example.com
2. How do you map the domain name to mappable.com
I'm using nginx as a web server. Do I have to use php or nodejs to manually edit the nginx config files?
I'm assuming you own example.com, they own mappable.com, and you want to allow them to use their domain mappable.com to access your subdomain mappable.example.com hosted on your server.
There are a few steps you'll need to do for this.
Set up wildcard DNS with your domain registrar so that all sub-domains will come to your one server.
Set up wildcard domain handling in nginx's conf on your one server so that all requests are sent to your code. You can do this using an underscore as the server name to make it the default server.
In your PHP code, you can check the headers to determine what domain the request is coming in through. Do a dump of $_SERVER to see what's in there. You will then know if the request came to mappable.com, mappable.example.com, etc...
Once you are in PHP with the domain or subdomain that was requested, you can act accordingly. You'll want to store the mapping of domain to subdomain in a database most likely. Additionally, you'll have to tell your users that they need to set up a cname, for example a cname of "mappable.com" to "mappable.example.com".
I think that should do what you need.

setcookie usage for multiple localhost subdomains

I have been working on a web application on my localhost (xampp) where I have two subdomains set up. Lets call these domains abc.localhost and xyz.localhost.
I have both of these set up in my host file to have an entry of
127.0.0.1 abc.localhost
127.0.0.1 xyz.localhost
I also have them set up in my vhost file like normal pointing to different locations.
My application is set up to go through abc.localhost first which is where i set up some cookies
setcookie('AUTHORIZATION', time()+3600, 0, '/', '.localhost');
setcookie('SOMEOTHERCOOKIE','here is the val',0,'/','.localhost');
this then forwards the user to xyz.localhost. In order for the user to get access to xyz.localhost the authorization has to be set by abc.localhost and pass over a cookie.
I have tried to change the ".localhost" to be xyz.localhost and every other combination i can think of. Leaving off the . does not work either.
Please help me figure this out. Thank you!
You can not set cookies for a top level domain (the last part of a domain). To achieve what you want change your HOST entries to abc.myproject.loc and xyz.myproject.loc or something alike.
Then you can set your cookies for myproject.loc.

Categories