Skip to content

Instantly share code, notes, and snippets.

@victorknust
Last active July 18, 2016 14:17
Show Gist options
  • Select an option

  • Save victorknust/e862465b8e6bb6b5de4d8dc180b35796 to your computer and use it in GitHub Desktop.

Select an option

Save victorknust/e862465b8e6bb6b5de4d8dc180b35796 to your computer and use it in GitHub Desktop.
WordPress Session
<?php
add_action( 'init', 'example_session_start', 1 );
add_action( 'wp_login', 'example_session_regenerate' );
add_action( 'wp_logout', 'example_session_end' );
function example_session_start() {
if ( !session_id() ) {
session_save_path( '/mnt/data/www/example.com/sessions' );
session_name( uniqid( 'example-', true ) );
session_start();
}
}
function example_session_regenerate() {
session_regenerate_id();
}
function example_session_end() {
session_destroy();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment