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
function get_string_between($string, $start, $end) { | |
$string = ' ' . $string; | |
$pos = strpos($string, $start); | |
if ($pos == 0) { | |
return ''; | |
} | |
$pos += strlen($start); | |
$len = strpos($string, $end, $pos) - $pos; | |
return substr($string, $pos, $len); | |
} |
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
const http = require('http'); | |
const fs = require('fs'); | |
const path = require('path'); | |
const server = http.createServer((req, res) => { | |
let filePath = path.join(__dirname, 'public', req.url === '/' ? 'index.html' : req.url); | |
const ext = path.extname(filePath); | |
let contentType = 'text/html'; | |
switch (ext) { |
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
function generate_random_id(length) { | |
var result = ''; | |
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
var charactersLength = characters.length; | |
for (var i = 0; i < length; i++) { | |
result += characters.charAt(Math.floor(Math.random() * charactersLength)); | |
} | |
return result; | |
} | |
</script> |
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
function check_date_in_range($date_from_user, $start_date, $end_date) { | |
$start_ts = strtotime($start_date); | |
$end_ts = strtotime($end_date); | |
$user_ts = strtotime($date_from_user); | |
return (($user_ts >= $start_ts) && ($user_ts <= $end_ts)); | |
} |
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
function getUserIP() { | |
if (preg_match("/^([d]{1,3}).([d]{1,3}).([d]{1,3}).([d]{1,3})$/", getenv('HTTP_X_FORWARDED_FOR'))) { | |
return getenv('HTTP_X_FORWARDED_FOR'); | |
} | |
return getenv('REMOTE_ADDR'); | |
} |
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
$hostnamefqdn = gethostbyaddr($_SERVER['REMOTE_ADDR']); | |
$periodpos = strpos($hostnamefqdn, '.'); | |
$hostname = substr($hostnamefqdn, 0, $periodpos); | |
// Put the SMB / NetBIOS Server IP inside of $serveripaddr - Replace 0.0.0.0 with your own | |
$serveripaddr = '0.0.0.0' | |
if (filter_var($hostnamefqdn, FILTER_VALIDATE_IP) !== false) { | |
// is an ip | |
$command = escapeshellcmd("/usr/bin/nmblookup -U " . $serveripaddr . " -A " . $hostnamefqdn); | |
$output = shell_exec($command); | |
error_log("NMB Lookup on IP: " . $output); |
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
function generate_random_string($length = 10) { | |
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; | |
$randomstring = ''; | |
for ($i = 0; $i < $length; $i++) { | |
$randomstring .= $characters[rand(0, strlen($characters) - 1)]; | |
} | |
return $randomstring; | |
} |
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
function linkify_string ($stringwithurl) { | |
return "<p>" . preg_replace('!(http|ftp|scp)(s)?:\/\/[a-zA-Z0-9.?&_\-\=/]+!', "<a target='_blank' href=\"\\0\">\\0</a>", $stringwithurl) . "</p>"; | |
} |
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 | |
// Simple Database Connection Code - PDO <-> MySQL/MariaDB Database | |
// Brian Wasner - 24 July 2014 0930 | |
$database_server = 'database_server_name_goes_here'; | |
$database_username = 'database_username_goes_here'; | |
$database_password = 'database_password_goes_here'; | |
$database_name = 'database_name_goes_here'; | |
try { |
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
import mysql.connector | |
from mysql.connector import Error | |
try: | |
connection = mysql.connector.connect(host='database_server', | |
database='database_name', | |
user='database_username', | |
password='database_password') | |
if connection.is_connected(): | |
db_Info = connection.get_server_info() |
OlderNewer