Reputation: 291
I am new to php. I have some silly php session doubts below:
session_set_cookie_params($params['lifetime'], '/folder1');
session_name('MYSITE_SID');
Q1) Above /folder1
means what? will cookie store under '/folder1'? so does cookie looks visible under folder1?
We have a websites like :
www.mysite.com/folder1
www.mysite.com/folder2
Q2) Can I keep same session_name
for above 2 folders of same website? or should keep different session names?
Note: If user already logged in 'www.mysite.com/folder1
', he should NOT be able to get loggedin automatically in www.mysite.com/folder2
Sorry for stupid queries. but please I wanna learn.
Upvotes: 2
Views: 216
Reputation: 2546
The path parameter in session_set_cookie_params
makes the server send a cookie header only when that path exists in the requested resource.Eg:
Set-Cookie: name=Nicholas; path=/blog
In this example, the path option would match /blog, /blogroll, etc.; anything that begins with /blog is valid. So it's not about cookie visibility through out your site but more of when the cookie will be set by the server. Read this for more info.
For your second question, you should use the same session name through out your site as I don't see a practical reason why you would need to change it IMHO. Finally, restricting parts of your site to users has more to do with AAA (Authentication, Authorization, and Accounting) than with sessions.
Good luck!
Upvotes: 2