Skip to content

Instantly share code, notes, and snippets.

View OkoyaUsman's full-sized avatar
🏠
Available for freelance job

Okoya Usman OkoyaUsman

🏠
Available for freelance job
View GitHub Profile
@OkoyaUsman
OkoyaUsman / timerange.php
Created January 4, 2018 13:06
Create time range function in php
<?php
// Below is a php time range function you can add in your php library and call it where you want to add time range dropdown.
function createTimeRange($startTime, $endTime, $interval = '15 mins', $format = '12') {
try {
if(!isset($startTime) || !isset($endTime)) {
throw new exception("Start or End time is missing");
}
$startTime = strtotime($startTime);
$endTime = strtotime($endTime);
$currentTime = time();
@OkoyaUsman
OkoyaUsman / AgeCalcFromDOB.php
Created January 4, 2018 13:00
Calculate Age from Date of Birth in PHP
<?php
function getAge($dob) {
$today = date("Y-m-d");
$diff = date_diff(date_create($dob), date_create($today));
return $diff->format('%yYears, %mMonths, %dDays');
}
// You can add the above function in your php library and use any where to calculate the age of the user by their date of birth.
echo getAge('19-10-1988');
// Output: 27Years, 10Months, 19Days
?>
@OkoyaUsman
OkoyaUsman / phpunzip.php
Created January 4, 2018 12:52
Unzip a ZIP file using php
<?php
/*
Here I have created a quick function in php to extract zip file.
Unzipping file is now very easy using php.
In php there is a function called ZipArchive::extractTo, using this predefined function you can easily extract zip archive.
*/
function unzip($file, $location) {
$zip = new ZipArchive;
if ($zip->open($file) === TRUE) {
@OkoyaUsman
OkoyaUsman / country-ip-redirect.txt
Created January 4, 2018 12:46
Redirect domain according to country IP address using php or .htaccess
Suppose you have three sub domain like http://au.example.com, http://ng.example.com, http://in.example.com Australia, Nigeria, India.
And If some one type http://example.com then he/she redirected county specific url as per geo ip location. Here is the solution.
// By PHP
First of all download geoplugin library and call it on your page.
http://www.geoplugin.com/_media/webservices/geoplugin.class.phps
<?php
require_once('geoplugin.class.php');
$geoplugin = new geoPlugin();
@OkoyaUsman
OkoyaUsman / detect-mobile-redirect.txt
Created January 4, 2018 12:34
How to detect mobile device and transfer visitor to mobile version of your website in PHP, JavaScript, Apache, jQuery, nginX,
This is quick tutorial about How to detect mobile device and transfer visitor to mobile version of your website.
If you don't have a mobile responsive website and you created separate mobile version of website.
If user open your website in mobile then he/she should automatically redirect mobile version of your website.
Then the following function will help you to achieve this goal.
Like you have seen in many popular website like facebook.com.
If you open facebook on mobile's browser you will be automatically redirected on their mobile version m.facebook.com.
// Here is the function in PHP
<?php
$useragent=$_SERVER['HTTP_USER_AGENT'];
@OkoyaUsman
OkoyaUsman / imgtransfer.php
Created January 4, 2018 12:10
3 ways to download and save a remote image on your server using PHP
<?php
/*
In this tutorial I am going to show you some PHP Methods By which you can easily download remote server image on your local server.
Suppose you don't have FTP access of images but you are able to access images via http port and you want to perform bulk image download.
Then these methods are very useful and you can try any of them to download and save a remote images on your server folder.
*/
// Method-1: By using simple copy() function in PHP
copy("REMOTE SERVER IMAGE URL", 'LOCAL SERVER PATH');
// ie:
@OkoyaUsman
OkoyaUsman / php2js-array.php
Last active November 14, 2024 22:36
How to Convert PHP Array into JavaScript Array
<?php
/*
You can easily use PHP array in javascript you only need to convert PHP array into JSON format Using json_encode() function.
PHP array can be converted to JavScript array and accessible in JavaScript.
Whatever the array type is, a single or multidimensional or indexed or associative array.
*/
//In PHP
var $booksArray = array("Book-1", "Book-2", "Book-3");
@OkoyaUsman
OkoyaUsman / dl.php
Created January 2, 2018 19:44
PHP 7.1+ File Download Generator
<?php
if(isset($_GET['signature'])){
ini_set('max_execution_time', 0);
$useragent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36";
$v = base64_decode($_GET['signature']);
parse_str($v);
if(!isset($mime)){
$mime = "video/mp4";
}
$extension = explode("/", $mime)[1];
@OkoyaUsman
OkoyaUsman / adblock-detector.js
Created December 26, 2017 23:51
AdBlock detector for Google AdSense. Detects if a user is using AdBlock or not and sends the tracking data to Google Analytics.
function AdblockDetector(){
}
AdblockDetector.prototype.run = function() {
var ad = document.querySelector("ins.adsbygoogle");
if(ad && ad.innerHTML.replace(/\s/g, "").length == 0) {
//Adblock detected
if(typeof ga !== 'undefined') {
ga('send', 'event', 'AdBlock', 'True', {'nonInteraction': 1}); //event hit will not be used in bounce-rate calculation.
}else if(typeof _gaq !== 'undefined') {
_gaq.push(['_trackEvent', 'Adblock', 'True', undefined, undefined, true]); //event hit will not be used in bounce-rate calculation.
@OkoyaUsman
OkoyaUsman / redirect-js.js
Created December 26, 2017 23:43
A simple random page redirector using Javascript. Note: Please don't forget to add comma , after each of the link (except the last link) and please put http:// or https:// in-front of each link.
var linkList = [
"https://google.com",
"https://yahoo.com",
"https://facebook.com",
"https://twitter.com",
"https://ebay.com",
"https://youtube.com"
];
var randomLink = linkList[Math.floor(Math.random()*linkList.length)];