会话修饰符

I'm using the following code:

session_set_cookie_params(-1,'/','myAwesomeDomain.com',true,true);

to secure the PHPSESSID cookie.

The problem is, that I can't change the cookie's name anywhere else with this:

session_name('_uid');

My question is: How to get these two methods to work with each other? Also, is there a method to refer to "When the browsing session ends" at the first parameter of the first method?

PS: There IS a session_start() in the file :D

EDIT: I even accept methods tinkering with the php.ini file.

EDIT v2: The file that contains this is separate from every other and it doesn't matter how many lines of code I need to do this. Using include_once().

EDIT v3: This is ridiculous. PHP puts a dot in front of the domain: sumPhpCookies
Now I'm totally lost why that is. (I'm not even using the session_name here.)

EDIT v4: Code:

<?php
// Somehow rename PHPSESSID cookie
session_set_cookie_params(-1,'/','www.forcemagic.xyz',true,true);
session_start(); ?>
session_name('_uid')

As the manual says, the name should contain of alphanumeric characters only (letters, digits), and is not allowed to consist of digits only, it must contain at least one letter.

So that underscore was actually the problem.

The session_name actually has to be declared before the session_set_cookie_params.

http://php.net/manual/en/function.session-set-cookie-params.php see the comment of "brandan, bildumgsroman.org"

The browser is client side. There is (unfortunately) no way to discover whether someone closed their browser or not, as it doesn't communicate anything back to the server about it (and that's where PHP resides). Sessions simply die off after the user hasn't reloaded the page within the specified lifetime. - A javascript solution is also highly inaccurate. (believe me, I've tried)

There is, however, one way to determine whether a browser has been closed or not. However, I wouldn't recommend it;

You could create a repetitive ajax call that stores a simple timestamp in the database that a user with a specific session is online. Then, you can run a cronjob on PHP checking that database for keepalive timestamps with a bigger difference between now and the last (2) ping(s), and then the cronjob will know that the browsing has stopped.