Cara menggunakan php session file location

Being unable to find an actual copy of mod_files.sh, and seeing lots of complaints/bug fix requests for it, here's one that works.  It gets all its parameters from PHP.INI, so you don't have the opportunity to mess up:

#!/bin/bash
#
# Creates directories for PHP session storage.
# Replaces the one that "comes with" PHP, which (a) doesn't always come with it
# and (b) doesn't work so great.
#
# This version takes no parameters, and uses the values in PHP.INI (if it
# can find it).
#
# Works in OS-X and CentOS (and probably all other) Linux.
#
# Feb '13 by Jeff Levene.

[[ $# -gt 0 ]] && echo "$0 requires NO command-line parameters.
It gets does whatever is called for in the PHP.INI file (if it can find it).
" && exit 1

# Find the PHP.INI file, if possible:
phpIni=/usr/local/lib/php.ini                        # Default PHP.INI location
[[ ! -f "$phpIni" ]] && phpIni=/etc/php.ini            # Secondary location
[[ ! -f "$phpIni" ]] && phpIni=                        # Found it?

# Outputs the given (as $1) parameter from the PHP.INI file:
# The "empty" brackets have a SPACE and a TAB in them.
#
PhpConfigParam() {
    [[ ! "$phpIni" ]] && return
    # Get the line from the INI file:
    varLine=`grep "^[     ]*$1[     ]*=" "$phpIni"`

    # Extract the value:
    value=`expr "$varLine" : ".*$1[     ]*=[     ]*['\"]*\([^'\"]*\)"`
    echo "$value"
    }

if [[ "$phpIni" ]]
then
    savePath=`PhpConfigParam session.save_path`
    # If there's a number and semicolon at the front, remove them:
    dirDepth=`expr "$savePath" : '\([0-9]*\)'`
    [[ "$dirDepth" ]] && savePath=`expr "$savePath" : '[0-9]*;\(.*\)'` || dirDepth=0
    bits=`PhpConfigParam session.hash_bits_per_character`
    case "x$bits" in
        x)    echo "hash_bits_per_character not defined.  Not running." ; exit 2 ;;
        x4) alphabet='0 1 2 3 4 5 6 7 8 9 a b c d e f' ;;
        x5) alphabet='0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v' ;;
        x6) alphabet='0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v'
            alphabet="$alphabet w x y z A B C D E F G H I J K L M N O P Q R S T U V W"
            alphabet="$alphabet X Y Z - ,"
            ;;
        *)    echo "unrecognized hash_bits_per_character.  Not running." ; exit 2 ;;
    esac
else
    echo "Cannot find the PHP.INI file.  Not running.  Sorry."
    exit 2
fi

# The depth of directories to create is $1.  0 means just create the named
# directory.  Directory to start with is $2.
#
# Used recursively, so variables must be "local".

doDir() {
    local dir="$2"
    if [[ -d "$dir" ]]
    then
        echo "Directory '$dir' already exists.  No problem."
    elif [[ -f "$dir" ]]
    then
        echo "FILE '$dir' exists.  Aborting." ; exit 2
    else
        if mkdir "$dir"
        then
            echo "Directory '$dir' created."
        else
            echo "Cannot create directory '$dir'.  Aborting." ; exit 2
        fi
    fi
    chmod a+rwx "$dir"
    if [[ $1 -gt 0 ]]
    then
        local depth=$(( $1 - 1 ))
        for letter in $alphabet
        do    doDir $depth "$dir/$letter"
        done
    fi
    }

echo "Running with savePath='$savePath', dirDepth=$dirDepth, and bitsPerCharacter=$bits."
sleep 3

#!/bin/bash
#
# Creates directories for PHP session storage.
# Replaces the one that "comes with" PHP, which (a) doesn't always come with it
# and (b) doesn't work so great.
#
# This version takes no parameters, and uses the values in PHP.INI (if it
# can find it).
#
# Works in OS-X and CentOS (and probably all other) Linux.
#
# Feb '13 by Jeff Levene.
0

#!/bin/bash
#
# Creates directories for PHP session storage.
# Replaces the one that "comes with" PHP, which (a) doesn't always come with it
# and (b) doesn't work so great.
#
# This version takes no parameters, and uses the values in PHP.INI (if it
# can find it).
#
# Works in OS-X and CentOS (and probably all other) Linux.
#
# Feb '13 by Jeff Levene.
1

jadi gini gan, ane lagi belajar PHP dan sekarang lagi belajar tentang cara kerja session pada server dan cookies pada client

nah ane mau tanya ini gan, jadi ane kan buat script login php itu dimana kalo username dan password nya sesuai dengan yang di database bakal masuk ke proses login dan ke halaman profil usernya dimana disitu ada session_start(); dan juga di bagian proses logout ada session_destroy(); ane sambil merhatiin file yang di buat di folder path-to-xampp/tmp dengan awalan "sess_*sessionid*". jadi setiap ane login dan ketemu session_start(); dibuatlah file session itu (sess_*sessionid*) dan ketika logout dan ketemu session_destroy();, file sess_*sessionid* nya ilang.. oke sampe sini ane ngerti konsepnya tentang temporary file itu..

trus ane coba login dan langsung tutup browser... sehingga cookies di browser ane ilang tapi file di servernya masih ada.. dan ketika ane buka browser dan ke php page ane, ane login lagi, karena cookies di browsernya dihapus pada saat tutup browser... dan pas ane login ternyata di xampp/tmp nya dia buat file session baru dari sebelumnya (yang sebelumnya masih ada)..

sampe sini ane coba bayangin kalo 1 juta orang lakuin gitu berarti ada 1 juta file di xampp/tmp yang sebenernya adalah sampah dong?

pertanyannya simpel aja gan, gimana caranya ngebersihin file sess_ yang udah gak kepake itu secara otomatis, entah secara periodik atau yang lain...

terimakasih
Cara menggunakan php session file location

Session PHP disimpan dimana?

Berbeda dengan cookies yang disimpan di browser, session disimpan di dalam web server.

Bagaimana cara kerja session pada PHP?

Cara kerja Session: Saat pengunjung mengakses suatu halaman, pengunjung tersebut memulai session (digunakan fungsi session_start()). Bila dalam konfigurasi php, session.auto_start diset ke 1 maka php akan melakukan start session secara otomatis.

Apa fungsi $_ session pada PHP?

Fungsi session adalah untuk melakukan aktivitas yang berhubungan dengan interaksi user pada sebuah web server php.

Apa itu session dalam website?

Berdasarkan definisi dari PPC Expo, metrik session di Google Analytics adalah kelompok interaksi yang tercatat ketika seseorang mengunjungi sebuah situs web dalam periode waktu tertentu.