I'm not quite sure what the purpose of session_names is.. Can someone please explain in what circumstances defining a name would be beneficial?
PHP: what is the purpose of session_name
i know you all mean well by recommending the software documentation, and in general encourage the skill to figure out answers on your own; its just that sometimes.. people need a more practical/pragmatic explanation. Of course I had looked up on php.net the definition of session_name.. and while that page showed me how to use session_name, it didn't specify why and in what cases!. Such clarifications often need additional help from our fellow peers. Thanks to icktoofay for the explanation below. A simple one minute answer.. no links necessary :-) –
Vicereine
moreover in this case, where it is very evident that @definitelyundefinable did not read said reference at all, or he would have understood that the reference is in no way clear that you can actually manage two sessions by assigning them two names... –
Lithia
And the irony @Vicereine is that SO doesn't like you to post these types of questions either, but I think they are way more valuable, for the reasons you stated. –
Illumine
You have two sites on the same domain. (say, a blog and a forum)
They both run different pieces of software.
If they ran on the same session and used the same variables in $_SESSION
, (say, user_id
), they would conflict.
session_name
lets you give each application a different session.
Why use two session we could use user_id_blog and user_id_forum right? I am newbie to programming and just asking. Will using session_name be more efficient in anyway? if yes could you care to explain how? –
Uri
@Geniusintrouble: If you've written both pieces of software, that may be an option; however, if they're huge codebases that you've never touched before, it may be easier to get it to use
session_name
than to track down wherever it touches $_SESSION
. –
Beating @icktoofay: And what about
session_id
. I have a shared server hosting, I tried to do the same, but do not face such a problem. However, days back I had used session_id()
to set the session_id
manually, then I faced a problem of Internal Server Error, when more than one client tried to connect to the same website. –
Larson @Veer:
session_id
might be used if PHP's default handling of the session ID is insufficient for some reason. I've never had to use it. –
Beating Nailed it @icktoofay, thanks. –
Illumine
The default is - I think - PHPSESSID. If you have more than one application on the same host, they would share those sessions. So, you should set different session names for each application, so that there is no weird stuff happening.
I am having problems with sessions on my site and some users losing their session. Half our site is WordPress which sets a PHPSESSID, and my booking process is self written and also sets a PHPSESSID. Do I simply use session_name("mysite") at the top of my buying process pages to avoid conflict? –
Carnelian
It's important to point out that not the same host is what may cause a conflict, but the same (most likely virtual) domain on that host. Different domains on the same host are fine with the same session name. –
Venable
© 2022 - 2024 — McMap. All rights reserved.