Showing posts with label PHP time. Show all posts
Showing posts with label PHP time. Show all posts

Friday, 2 August 2019

How to get the current UNIX timestamp using PHP

UNIX TIMESTAMPIs the time measured in seconds since the start of the Unix epoch “1 January 1970”
Use the PHP time function as per example below
echo time(); //Will print out the current timestamp
 
//OUTPUT: 1285365600

Friday, 5 June 2015

PHP: Date and time example

<?php
$time = time();
print date("m/d/y G.i:s", $time);
print "<br>";
print "Today is ";
print date("j of F Y, \a\\t g.i a", $time);
?>

PHP: Some date and time examples

<?php
$theDate = time();
print date('d-m-y',$theDate);
print ("<br>");
print date('d-m-Y',$theDate);
print ("<br>");
print date('D-M-Y',$theDate);
print ("<br>");
print date('G-i-s',$theDate);
?>

Monday, 23 February 2015

PHP: Generate an alpha-numeric password salt

<?php
/**
 * This function generates an alpha-numeric password salt (with a default of 32 characters)
 * @param $max integer The number of characters in the string
 *
 */
function generateSalt($max = 32) {
$baseStr = time() . rand(0, 1000000) . rand(0, 1000000);
$md5Hash = md5($baseStr);
if($max < 32){
$md5Hash = substr($md5Hash, 0, $max);
}
return $md5Hash;
}

//Usage:
/*
echo "Salt with 32 characters:\n";
echo generateSalt() . "\n";
echo "Salt with 5 characters:\n";
echo generateSalt(5) . "\n";
*/
?>