0

So I've just found out that this line breaks my session handling in my PHP application:

session_set_cookie_params($ttl, '/', '.example.com'); 

Pretty logical though. I shouldn't be able to set a cookie exclusive to the example.com and assume that it will work when I run the application at a staging server in the LAN.

But to the question, what domain should I enter to make this work when running my application at my LAN-based staging server which is accessed at 192.168.1.100 ?

Thanks

2 Answers 2

3

Just put the IP in there, it qualifies as host as well:

session_set_cookie_params($ttl, '/', '192.168.1.100'); 

If it's localhost, you can use it as well:

session_set_cookie_params($ttl, '/', 'localhost'); 

or if your server in the LAN has a hostname, put in that hostname (localhost does not work in LAN across multiple boxes naturally).

Sign up to request clarification or add additional context in comments.

3 Comments

Oh. But what about the prefixing dot? I need to make sure to prefix with that dot when running in production environment to allow cookies in subdomains, right?
Yeah but your question was not about the production server but the LAN server. As the LAN server has no subdomain and is just an IP, well, what do you worry about?
Yep, just wanted to make sure that I've got it all right. Thank you!
2

Isn't it better to make entry into your hosts file and name your staging server?

Example row inside hosts file:

192.168.1.100 preview.example.com 

See http://en.wikipedia.org/wiki/Hosts_(file)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.