Logout for Private Messaging on Your Website
- Private Messaging on Your Website
- Private Message Login
- Private Message Logout
- Private Message Sending Form
- Send Private Message
- Private Message Inbox — Received Messages
- Private Message Outbox — Sent Messages
- Check Private Message Session ID
- Delete Received Private Message
- Delete Sent Private Message

This page is a tutorial on putting a private messaging (PM) logout script on your website. It uses sessions and both JavaScript and PHP. The screenshot above is the private message inbox.
Let's check out the code. It starts with a PHP include function: include_once"checkid.php". This gets a session started. You need to do this before doing other session actions. The include file contains this script:
session_start();
if(!isset($_SESSION['sessionid'])){
session_unset();
session_destroy();
header('location: message-login.php');
}else{
// session logged
}
Now that we have established the fact that a legitimate user is trying to logout, we unset the session and then destroy the session. This is the correct protocol for ending sessions but you have to start the session with session_start() if these session functions are going to work. Finally, we send the user a friendly "See you soon!" message and send him back to the login script. You may have a better destination in mind, since all these private messaging apps are for installing private messaging on your website. It's up to you.
Name this file message-logout.php
<?php
include_once"checkid.php";
// message-logout.php
session_unset();
session_destroy();
echo '<script language="javascript">alert("See you soon!"); window.location = "message-login.php"; </script>';
?>