Skip to content

Instantly share code, notes, and snippets.

View gaffling's full-sized avatar
🕚
I don't have time to hurry!

Igor Gaffling gaffling

🕚
I don't have time to hurry!
View GitHub Profile
@gaffling
gaffling / checkMime.php
Created April 3, 2021 12:32
[Check Mime Type] Check if URl is a given MimeType #php #function #mime
/* ----------------------------------------------------------------------- */
/* [Check Mime Type] Check if URl is a given MimeType #php #function #mime */
/* ----------------------------------------------------------------------- */
function checkMime($url, $mime='application/pdf') {
// MP3 = 'audio/mpeg' - PDF = 'application/pdf'
if (!function_exists('curl_init')) die('ERROR - Please install CURL on your PHP!');
$a = parse_url($url);
if (checkdnsrr(str_replace('www.','',$a['host']),'A') or checkdnsrr(str_replace('www.','',$a['host']))) {
$ch = @curl_init();
@gaffling
gaffling / doSMTPValidation.php
Created April 3, 2021 12:19
[Mail Validation] Use SMTP to validate eMail Address #php #function #mailcheck
/* ------------------------------------------------------------------------------ */
/* [Mail Validation] Use SMTP to validate eMail Address #php #function #mailcheck */
/* ------------------------------------------------------------------------------ */
function doSMTPValidation($email, $probe_address='', $debug=false) {
$output = '';
if (!$probe_address) $probe_address = $_SERVER['SERVER_ADMIN'];
if (preg_match('/^([a-zA-Z0-9\._\+-]+)\@((\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,7}|[0-9]{1,3})(\]?))$/', $email, $matches)) {
$user = $matches[1];
@gaffling
gaffling / getLatLong.php
Created April 3, 2021 11:56
[getLatLong] Get lat and long coordinatesby address from Google Maps #php #function #geo
/* ---------------------------------------------------------------------------------------- */
/* [getLatLong] Get lat and long coordinatesby address from Google Maps #php #function #geo */
/* ---------------------------------------------------------------------------------------- */
function getLatLong($address){
if (!is_string($address)) die('ERROR - Address must be a string!');
$url = sprintf('https://www.google.com/maps/place/%s', rawurlencode($address));
$result = file_get_contents($url);
preg_match('!center=(-?\d+\.\d+)%2C(-?\d+\.\d+)&zoom=!U', $result, $match);
$_coords['lat'] = $match[1];
@gaffling
gaffling / getHttpResponseCode.php
Created April 3, 2021 10:37
[get HTTP Response Code] Get HTTP Header Response Code from Server #php #function #httpcode
/* ------------------------------------------------------------------------------------------- */
/* [get HTTP Response Code] Get HTTP Header Response Code from Server #php #function #httpcode */
/* ------------------------------------------------------------------------------------------- */
function getHttpResponseCode($url) {
if (!function_exists('curl_init')) die('ERROR - Please install cURL on your PHP!');
$ch = @curl_init($url);
@curl_setopt($ch, CURLOPT_HEADER, TRUE);
@curl_setopt($ch, CURLOPT_NOBODY, TRUE);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
@gaffling
gaffling / googleSuggestKeywords.php
Created April 3, 2021 09:45
[Google Suggest] Get all the related keywords from Google Suggest #php #function #GoogleSuggest
/* ----------------------------------------------------------------------------------------------- */
/* [Google Suggest] Get all the related keywords from Google Suggest #php #function #GoogleSuggest */
/* ----------------------------------------------------------------------------------------------- */
function googleSuggestKeywords($keyword, $only_one_keyword_allowed=false) {
if (!function_exists('curl_init')) die('ERROR - Please install cURL on your PHP!');
if ($only_one_keyword_allowed==true) { // IF JUST ONE WORD ALLOWED
$keyword = explode(' ', $keyword);
$keyword = $keyword[0];
}
@gaffling
gaffling / url2pdf.php
Created April 3, 2021 09:43
[URL2PDF] pdflayer.com API to generate a PDF from an URL #php #function #pdf
/* ---------------------------------------------------------------------------- */
/* [URL2PDF] pdflayer.com API to generate a PDF from an URL #php #function #pdf */
/* ---------------------------------------------------------------------------- */
function url2pdf($url, $licensekey='a2ce7bfc1f9be9d8ca741365fc532ab2') {
// GET YOUR API ACCESS KEY - https://pdflayer.com/dashboard
ini_set('user_agent', 'Mozilla/5.0');
$api = 'http://api.pdflayer.com/api/convert?access_key=' . $licensekey . '&document_url=' . $url;
$filename = str_replace('www.', '', pathinfo($url, PATHINFO_FILENAME) . '.pdf');
if (!headers_sent()) {
header('Content-type: application/pdf');
@gaffling
gaffling / betterVersion.php
Last active July 23, 2021 12:45
[Geo IP] Get Geo Data of a given IP #php #function #geo
// https://www.geoplugin.com/examples
function ipInfo($ip = NULL, $purpose = "location", $deep_detect = TRUE) {
if ( isBot() ) return false;
$output = NULL;
if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) {
$ip = $_SERVER["REMOTE_ADDR"];
if ($deep_detect) {
if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP))
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP))
@gaffling
gaffling / filesize_url.php
Created March 31, 2021 13:42
[FileSize URL] Get FileSize of an URL without downloading the file #php #function #filesize
/* ------------------------------------------------------------------------------------------- */
/* [FileSize URL] Get FileSize of an URL without downloading the file #php #function #filesize */
/* ------------------------------------------------------------------------------------------- */
function getRemoteFileSize($url) {
ini_set('user_agent', 'Mozilla/5.0');
if (substr($url,0,4)=='http') {
$header = array_change_key_case(get_headers($url, 1), CASE_LOWER);
#echo'<pre>';var_dump($$header);
if ( strcasecmp($header[0], 'HTTP/1.1 200 OK') != 0 ) {
@gaffling
gaffling / shortener.php
Last active March 31, 2021 13:24
[URL Shortener] Shorten URL and preview shortend URL in long #php #function #urlshortener
/* ----------------------------------------------------------------------------------------- */
/* [URL Shortener] Shorten URL and preview shortend URL in long #php #function #urlshortener */
/* ----------------------------------------------------------------------------------------- */
function doShortURL($url) {
// thanks to tinyurl.com
return file_get_contents('http://tinyurl.com/api-create.php?url=' . $url);
}
function doLongURL($url) {
@gaffling
gaffling / card_faces.svg
Created March 16, 2021 15:19
[SVG Card Faces] #svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.