This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Reset Magento 2 admin password in phpmyadmin | |
Go to phpmyadmin and copy the following sql query: | |
UPDATE admin_user SET password = CONCAT(SHA2('_CRYPT_KEY_YourNewPassword', 256), ':_CRYPT_KEY_:1') WHERE username = 'admin'; | |
The _CRYPT_KEY_ is a cryptographic salt, it's located in app\etc\env.php file | |
<?php | |
return array ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://php.net/manual/en/datetime.formats.php | |
<?php | |
$dateTime = new DateTime('2016-01-01'); | |
echo $dateTime->format('Y-m-d H:i:s');` //Output: 2016-01-01 00:00:00 | |
$dateTime = new DateTime(); | |
echo $dateTime->format('Y-m-d H:i:s');`//Output: whatever the current date is, correctly formatted. | |
//DateTime and Timestamps | |
//Format an unreadable timestamp into a nice and shiny easy-to-read date |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$ids = ["1","2","3","4"]; | |
$idsStr = implode(',', $ids); | |
SELECT * FROM table WHERE id IN ('.$idsStr.') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getMondays($y, $m) | |
{ | |
return new DatePeriod( | |
new DateTime("first monday of $y-$m"), | |
DateInterval::createFromDateString('next monday'), | |
new DateTime("last day of $y-$m") | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getClientIP() { | |
$ipaddress = ''; | |
if (isset($_SERVER['HTTP_CLIENT_IP'])) | |
$ipaddress = $_SERVER['HTTP_CLIENT_IP']; | |
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) | |
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR']; | |
else if(isset($_SERVER['HTTP_X_FORWARDED'])) | |
$ipaddress = $_SERVER['HTTP_X_FORWARDED']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$files = glob("folder/*"); | |
if($files){ | |
$now = time(); | |
foreach ($files as $file) { | |
if (is_file($file)) { | |
if ($now - filemtime($file) >= 60 * 60 * 24 * 5) { // older then 5 days | |
unlink($file); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//used 173.174.103.34 as example | |
echo file_get_contents('https://ipapi.co/173.174.103.34/json'); | |
//result | |
/* | |
{ | |
"ip": "173.174.103.34", | |
"version": "IPv4", | |
"city": "Austin", | |
"region": "Texas", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$i = 0; | |
$len = count($array); | |
foreach ($array as $item) { | |
if ($i == 0) { | |
// first | |
} else if ($i == $len - 1) { | |
// last | |
} | |
// … |