Rectangle 27 785

"kill" will only kill one screen window. To "kill" the complete session, use quit.

$ screen -X -S [session # you want to kill] quit

type 'exit' (without the quotes) in ubuntu :P

exit works but needs to be typed into each screen that was opened. quit does not even work

@kapad actually quit works if you write it inline -X -S pid/sockname quit

screen -X quit

linux - Kill detached screen session - Stack Overflow

linux gnu kill gnu-screen
Rectangle 27 12

To kill all detached screen sessions, include this function in your .bash_profile:

killd () {
for session in $(screen -ls | grep -o '[0-9]\{5\}')
do
screen -S "${session}" -X quit;
done
}
killd

Sometimes it's not 5 digits, so i use: killd () { for session in $(screen -ls | grep -o '[0-9]\+') do screen -S "${session}" -X quit; done }

linux - Kill detached screen session - Stack Overflow

linux gnu kill gnu-screen
Rectangle 27 2

If you aren't using cookies to preserve your users' login information, it should log them out when they close the browser, because any session cookies should be killed when the browser closes.

Obviously this isn't always the case (see here for an example of Firefox preserving login information after logging out) because "session restore" features we now blur the line between what is considered a "single browser session". (Personally, I think this should be classified as a bug, but that is only my opinion).

There are two possible techniques. The first would be (as yojimbo87 mentions before me) to use web sockets to keep a connection between client and server, and when the socket closes, kill the session. The issue here is that web sockets support is limited, and certainly not possible on anything other than bleeding edge browsers (FF4, Chrome, IE9, etc).

An alternative could be to use AJAX to constantly poll the server to tell it that the page is still being viewed, so if, for example, you send a keep-alive request via AJAX every 30 seconds, you'd store the timestamp of the request in the session. If the user then comes back to the page and the time difference between the current request and the last request is more than say... 45 seconds (accounting for latency), you'd know that the user closed their browser and need to log in again.

In both of these situations, there is however a fatal flaw, and that is that they rely on JavaScript. If the user doesn't have JavaScript enabled, you'd end up ruining the user experience with constant login prompts, which is obviously a bad idea.

In my opinion, I think its reasonable to simply rely on session cookies being deleted by the browser when the user closes the browser window, because that is what they are supposed to do. You as a developer can't be blamed when the client browser performs undesirable behaviour, since its entirely out of your hands, and there's no functional workaround.

javascript - Is there a reliable way to log a user out when the browse...

javascript asp.net session asp.net-membership
Rectangle 27 1

Unfortunately due to the explicit nature of the web and the fact there is no permanent link between a website server and a users browser it is impossible to tell when a user has closed their browser. There are events and JavaScript which you can implement (e.g. onunload) which you can use to place calls back to the server which in turn could 'kill' a session - Session.Abandon();

You can set the timeout length of a session within the web.config, remember this timeout is based on the time since the last call to the server was placed by the users browser.

Browser timedout did not added.

How do I explicitly set asp.net sessions to ONLY expire on closing the...

asp.net session
Rectangle 27 5

It only does that for the current session weirdfully. Outside of emacs it is not removed from the kill ring!

Emacs: how to delete text without kill ring? - Stack Overflow

emacs
Rectangle 27 5

It only does that for the current session weirdfully. Outside of emacs it is not removed from the kill ring!

Emacs: how to delete text without kill ring? - Stack Overflow

emacs
Rectangle 27 12

You could try to force PHP to delete all the sessions by doing

ini_set('session.gc_max_lifetime', 0);
ini_set('session.gc_probability', 1);
ini_set('session.gc_divisor', 1);

That forces PHP to treat all sessions as having a 0-second lifetime, and a 100% probability of getting cleaned up.

The drawback is that whichever unlucky user runs this first will get a long pause while PHP does cleanup, especially if there's a lot of session files to go through.

if ($_SESSION['username'] == 'user to delete') {
     session_destroy();
 }

PHP's garbage collector isn't controllable, so you can't give it parameters such as "delete all sessions except for user X's". It looks strictly at the last-modified/last-accessed timestamps on the session files and compares that to the max_lifetime setting. It doesn't actually process the session data.

to remove a session in your second code is only locally. $_SESSION variable is independent of each user, my aim is to be able to have all sessions for all users to destroy who ever is logged in

yes, but you said you wanted to log out one, or all, users. The ini-set stuff takes care of everyone. the if() takes care of a particular user.

Does it not work in recent versions? I'm using wampserver 2.5 with apache 2.4.9 and php 5.5.x. This delete not even one sess_* files stored at the tmp directory at all, except only session_destroy() delete the current session's file.

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

How to kill a/all php sessions? - Stack Overflow

php session login
Rectangle 27 2

I figured that the problem was to kill the all process tree and That SO answer solves the problem

setpgrp(0, 0);
kill 9, -$pid;
my $pid = fork();
die "unable to fork: $!" unless defined($pid);
if (!$pid) {  # child
    setpgrp(0, 0);
    exec("tail -f $logfile | logger -t $ENV{SUDO_USER}:$target ");
    die "unable to exec: $!";
}

$show_cmd && print "% $cmd\n" ;
system $cmd or die "exec() failed: $!\n" ;
printf "Session end pid to kill %d\n", $pid;
kill 9, -$pid;
waitpid $pid, 0;
printf "End of the script.\n";

ssh - Perl fork exec, system in parent and kill child - Stack Overflow

perl ssh exec fork kill
Rectangle 27 1

I had to kill all existing SSH sessions with

pkill -o -u YOURUSERNAME sshd

macos - Opening file with Sublime Text via SSH to VM, error - Stack Ov...

macos ubuntu ssh virtual-machine sublimetext2
Rectangle 27 1

You didn't kill the session that way, you just unset a variable that held session ID. If you did:

$unsetMe = session_id();
unset($unsetMe);

you'd just unset a variable, nothing would be done to a session. You need to use:

session_destroy();

php - session_id() error - Stack Overflow

php session sessionid
Rectangle 27 5

Use session_destroy to destroy the session data and session_unset to clear the $_SESSION variable respectively.

Furthermore, call session_regenerate_id(true) after an authentication attempt to change the current sessions ID and destroy the session data that is still associated to the old session ID.

Where do I put the session_destroy statement?

@Nerd With A Vengeance: Call it where you want the current session to be destroyed. Note to call session_start before, otherwise the session will not be loaded.

This answer is not complete. You still need to unset the session variables and invalidate the session cookie if it exists.

How do I kill a PHP session? - Stack Overflow

php session
Rectangle 27 2

Clearling all sessions at once would require first knowing which session.save_handler is being used to store sessions and locating the session.save_path in order to delete all sessions. For deleting the current session only, refer to the documentation for session_destroy().

Here are some common examples for deleting all sessions using standard file and memcached save handlers:

foreach(glob(ini_get("session.save_path") . "/*") as $sessionFile) {
    unlink($sessionFile);
}
$memcached = new Memcached;
$memcached->addServers($listOfYourMemcachedSesssionServers);

// Memcached session keys are prefixed with "memc.sess.key." by default
$sessionKeys = preg_grep("@^memc\.sess\.key\.@", $memcached->getAllKeys());
$memcached->deleteMulti($sessionKeys);

Of course, you might want to consider only doing this out of band from your normal HTTP client requests, since cleaning up large session storage may take some time and have inadvertent side effects in a normal request life cycle.

How to kill a/all php sessions? - Stack Overflow

php session login
Rectangle 27 5

This code is based from the official PHP site, and another well written snippet on SO.

<?php
// Finds all server sessions
session_start();
// Stores in Array
$_SESSION = array();
// Swipe via memory
if (ini_get("session.use_cookies")) {
    // Prepare and swipe cookies
    $params = session_get_cookie_params();
    // clear cookies and sessions
    setcookie(session_name(), '', time() - 42000,
        $params["path"], $params["domain"],
        $params["secure"], $params["httponly"]
    );
}
// Just in case.. swipe these values too
ini_set('session.gc_max_lifetime', 0);
ini_set('session.gc_probability', 1);
ini_set('session.gc_divisor', 1);
// Completely destroy our server sessions..
session_destroy();
?>

Works well. Servers like NGinx you can turn off, clean cache, swipe memory reset, clear logs etc and generally remove temp usage. Even drop the limits of memory.

does not work :/

this only kills current session, im using share hosting so i dont have much access to everything. I wanted to kill all current authed sessions if any

How to kill a/all php sessions? - Stack Overflow

php session login
Rectangle 27 3

I had a similar problem today. I was transferring a 100GB file over a 1MBps link, and it was halfway into the transfer when my workstation crashed. I brought PuTTY back up and got on my terminal server, but no combination of the detach / reattach commands would work. I decided i would kill screen, so i checked ps to get the PID. While i was looking at the PS output, i noticed that the BASH session i had used to launch Screen was still running. On a whim, i decided to kill that session instead of screen, thinking "This should be like closing the PuTTY window, which allows me to re-attach." Sure enough, i was able to run "screen -dr" succesffully.

linux - Cannot detach screen session - Stack Overflow

linux gnu-screen
Rectangle 27 3

You can use session_save_path() to find the path where PHP saves the session files, and then delete them using unlink().

Be very careful with this approach if the path in question turns out to be the global /tmp directory! There's bound to be other processes other than PHP storing temporary data there. If PHP has its own directory set aside for session data it should be fairly safe though.

Obviously this isn't a good practice - but I'm just giving the man what he wants! :-p

thanks, but what other method, using php buildin methods.

This is the best answer for what OP asked, except it does not address systems where Session is not stored on the file system (eg in the database as KARASZI Istvn mentioned).

How to kill a/all php sessions? - Stack Overflow

php session login
Rectangle 27 3

If you're using PHP session storage, then they may be in the temporary directory of your server. Deleting the selected files will "kill" the session.

A nicer solution is to use a database session storage and delete the selected sessions from there. You can check out HTTP_Session2 which has multiple containers.

You mean PHP session storage?

How to kill a/all php sessions? - Stack Overflow

php session login
Rectangle 27 5

Nohup allows a client process to not be killed if a the parent process is killed, for argument when you logout. Even better still use:

nohup /bin/sh -c "echo \$\$ > $pidfile; exec $FOO_BIN $FOO_CONFIG  " > /dev/null

Nohup makes the process you start immune to termination which your SSH session and its child processes are kill upon you logging out. The command i gave provides you with a way you can store the pid of the application in a pid file so that you can correcly kill it later and allows the process to run after you have logged out.

Linux: Prevent a background process from being stopped after closing S...

linux process ssh background-process
Rectangle 27 5

Nohup allows a client process to not be killed if a the parent process is killed, for argument when you logout. Even better still use:

nohup /bin/sh -c "echo \$\$ > $pidfile; exec $FOO_BIN $FOO_CONFIG  " > /dev/null

Nohup makes the process you start immune to termination which your SSH session and its child processes are kill upon you logging out. The command i gave provides you with a way you can store the pid of the application in a pid file so that you can correcly kill it later and allows the process to run after you have logged out.

Linux: Prevent a background process from being stopped after closing S...

linux process ssh background-process
Rectangle 27 12

The form button is just like any other form button, nothing special. Catch the POST on the php side of things, and use session_destroy(); to kill the session data entirely.

More info about forms and PHP and how to work with the data from the form: http://www.tizag.com/phpT/forms.php

<html><body>
<h4>Tizag Art Supply Order Form</h4>
<form action="process.php" method="post">
<input type="submit" />
</form>
</body></html>
<html><body>
<?php
session_destroy();
?>
</body></html>

This is correct, but I think the person is asking for you to write the code for them. If not, my mistake. +1 though.

Not a problem..give me a minute :-D

Not so much write the code as explain where the php gets put (I don't know if I'm making much sense). I saw the short code <?php session_start(); session_destroy(); ?> but do not know where it gets put or how to call it. I tried putting it in an external .php file, and using action= to call it, but my browser simply tries to open the php file when I try clicking this.

Right, so you'll need something like XAMPP. apachefriends.org/en/xampp.html This installs a local copy of apache and everything you need to get going. Store your scripts/programs in the htdocs sub-folder under the XAMPP folder. Then access the script using localhost/folder/script.php in your Browser. Be certain that the XAMPP Apache Server is running before calling the script. You can tell via the XAMPP control panel. :-)

html - How to destroy the php session with one button - Stack Overflow

php html session logout destroy