Skip to content

Instantly share code, notes, and snippets.

View simonrjones's full-sized avatar

Simon R Jones simonrjones

View GitHub Profile
@simonrjones
simonrjones / delete-php-sessions.php
Last active August 29, 2015 14:16
Delete PHP sessions from the tmp folder when you have 10,000s of them which cannot be removed with a simple rm -f /tmp/sess_* command
<?php
// Clean PHP session files when you have 10,000s of them!
// Set this to the folder that contains your session files with trailing slash
// @see http://php.net/manual/en/function.session-save-path.php
$sessionTmpFolder = '/path/to/tmp/';
$x=0;
foreach (range(0,9) as $number) {
foreach (range('a','z') as $letter) {
@simonrjones
simonrjones / back-page-link.js
Created December 4, 2014 19:05
JavaScript back to last page link
@simonrjones
simonrjones / parseCsv.php
Last active August 29, 2015 14:10
Parse CSV file snippet
<?php
// Read CSV file
// PHP5.4+
ini_set('auto_detect_line_endings', true);
$file = new SplFileObject("path/to/file.csv");
$file->setFlags(SplFileObject::READ_CSV);
$line = 0;
$headers = [];
foreach ($file as $row) {
<?php
// Error reporting
error_reporting(E_ALL);
ini_set('display_errors', true);
// Return the Apache user
$tmpFilename = tempnam('/tmp', 'TEST');
$handle = fopen($tmpFilename, 'w');
fwrite($handle, 'testdata');
fclose($handle);