This function bundles the ability to create a custom directory and use that for the save path of session files. But if the directory already exists, it will be used for saving the session files without any modifications. This function needs to be called before session_start()
<?php
function SaveCustomSession($dir)
{
// Check if the directory already exists
if (!is_dir($dir))
{
// Set created to false
$created = false;
// If dir created
if (mkdir($dir))
// Set created to true
$created = true;
// If created = false
if (!$created)
return false;
}
// If the directory exists or has been created, use as save path
session_save_path($dir);
}
?>
Create quickly a custom directory for session files example
// Specify session files save path
SaveCustomSession('C:\server\sessions');
// Initialize session
session_start();
Mail this!
- Comments (0)
- PingBacks (0)
- TrackBacks (0)

» Latest comments