Skip to main content

Posts

Showing posts with the label server

The 'localhost.run', an alternative of 'ngrok'

What is ngrok? ngrok is a cross-platform application that enables developers to expose a local development server to the Internet with minimal effort. The software makes your locally-hosted web server appear to be hosted on a subdomain of ngrok.com , meaning that no public IP or domain name on the local machine is needed. Problem with ngrok Usually ngrok CLI tool and ngrok.com URL are blocked on corporate systems. Although there are many alternatives of ngrok but all of them requires their specific CLI tool to be downloaded but those fails to pass through corporate network. Most suitable alternative of ngrok Now we have got https://localhost.run/ as the best alternative of ngrok because of no specific CLI tool is required to be downloaded. How to setup localhost.run? To setup you need to generate SSH key and add it to the ssh-agent. Follow this article, Generating a new SSH key and adding it to the ssh-agent to do that. How to use localhost.run? Open the folder which you want to...

PHP: Session based RAM

Here is a session based RAM. <? /** * @Class: CContainerManager.class.php * @Author: Abhishek Kumar (c) 2008. **/ class ContainerManager { function __construct() { session_start(); Get(); } function Get() { global $Container; $Container = array(); if (isset($_SESSION['RAM'])) { $Container = unserialize($_SESSION['RAM']); } } function Set() { $_SESSION['RAM'] = serialize($GLOBALS['Container']); } function Clean() { if (isset($_SESSION['RAM'])) { unset($_SESSION['RAM']); unset($GLOBALS['Container']); } } function Add($Associate, $Value) { global $Container; if (!isset($Container[$Associate])) { $Container[$Associate] = $Value; return true; } else { return false; } } function Modify($Associate, $Value) { global $Container; if (isset($Container[$Associate])) { $Container[$Associate] = $Value; return true; } els...

PHP: Webpage Publisher

A webpage publishing class. <?php /** * @Class: CPublisher.class.php * @Author: Abhishek Kumar **/ require_once("CTemplate.class.php"); require_once("CFile.class.php"); class CPublisher { private static $oTemplate; public static function initialize() { self::$oTemplate = new CTemplate(); self::$oTemplate->setTemplatePath('asset/template'); } public static function Publish($iContent, $iInclude) { self::initialize(); $Output = self::$oTemplate->ModifyAndDump('Container.dt', array( 'Header'=>self::getHeader($iInclude), 'Content'=>self::$oTemplate->ModifyAndDump('ContainerBody.dt', array( 'Header'=>self::$oTemplate->Dump('Header.st'), 'Content'=>$iContent, 'Footer'=>self::$oTemplate->Dump('Footer.st') ) ), ) ); return $Output; } private static function getHeader($iI...

PHP: Image Uploader

Here is an image uploader with re-sizing methods <?php /** * @file ImageUploader.php * @author Abhishek Kumar **/ $tempFile = $_FILES['Filedata']['tmp_name']; $fileName = $_FILES['Filedata']['name']; $fileSize = $_FILES['Filedata']['size']; $timestamp = date("YmdHis"); $new_fileName = "IMG".$timestamp.strtolower(getFileExtension($fileName)); move_uploaded_file($tempFile, "warehouse/" . $new_fileName); echo $new_fileName; function getFileExtension($iFile) { $iExtension = strrpos($iFile, "."); $oExtension = substr($iFile, $iExtension, strlen($iFile)); $oString = strtolower($oExtension); return $oString; } function imageResizer($image) { //$image = "Database/Foto/IMG_001.jpg"; // Name of the source image list($PictureWidth, $PictureHeight) = getimagesize($image); // Get original size of source image $PictureAspectRatio = $PictureWidth/$PictureHeight; $Width = 160;...

PHP: Directory Handlers

Directory handling methods. <?php /** * @Class: CDirectory.class.php * @Author: Abhishek Kumar **/ require_once("CTemplate.class.php"); require_once("CFile.class.php"); class CDirectory { private $VoTemplate; private $VoCFile; private $Avoid; public function __construct() { $this->VoTemplate = new CTemplate(); $this->VoCFile = new CFile(); $this->Avoid = array(); $this->Avoid['Directory'] = array(); $this->Avoid['File'] = array(".", ".."); $this->Avoid['Extension'] = array(); } public function Directory($iCommand, $iDir) { switch($iCommand) { case 'CREATE': mkdir($iDir, 0700); $oStatus = true; break; case 'REMOVE': rmdir($iDir); $oStatus = true; break; case 'DELETE': $this->deleteDir($iDir); $oStatus = true; break; default: $oStatus = false; } return $oStatus; } private ...

PHP: File Utilities Methods

Utility methods for file handling. <?php /** * @Class: CFile.class.php * @Author: Abhishek Kumar **/ class CFile { public function getFileExtension($iFile) { $iExtension = strrpos($iFile, "."); $oExtension = substr($iFile, $iExtension, strlen($iFile)); $oString = strtolower($oExtension); return $oString; } public function getFileName($iFile) { $iExtension = strrpos($iFile, "."); $oFileName = substr($iFile, 0, $iExtension); return $oFileName; } public function getFileExtensionAlt($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } public function getFileNameAlt($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $filename = substr($str,0,$i); return $filename; } public function CreateFile($iFileName) { if (!$handle = fopen($iFileName, 'w+')) { return "Error: Ca...

PHP: Template Setter

A template setting class for a webpage. <?php /** * @Class: CTemplate.class.php * @Author: Abhishek Kumar **/ require_once("CFile.class.php"); class CTemplate { private $HandleFile; private $Template; private $TemplatePath; public function __construct() { $this->HandleFile = new CFile(); } public function __destruct() { unset($this->HandleFile); } public function FitIn($iTemplate, $iTemplateArgument) { $this->Template = $iTemplate; $this->Template = $this->setTemplate($iTemplateArgument); return $this->Template; } public function ModifyAndDump($iTemplateName, $iTemplateArgument) { $this->Template = $this->getTemplate($iTemplateName); $this->Template = $this->setTemplate($iTemplateArgument); return $this->Template; } public function Dump($iTemplateName) { $this->Template = $this->getTemplate($iTemplateName); return $this->Template; } public function setTemplatePath($iPath...

PHP: Web-service for communicating with MySQL database

Here is a php to mysql communication gateway packaged as a web-service. Gateway.php <?php require_once('Config.php'); require_once('engine/CMySqlManager.class.php'); $VoCMySqlManager = new CMySqlManager(); $VoCMySqlManager->Connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_SCHEMA); $_POST['message'] = (!isset($_POST['message']))? null : $_POST['message']; $_GET['message'] = (!isset($_GET['message']))? null : $_GET['message']; $C2S_message = ($_POST['message'] == null)? $_GET['message'] : $_POST['message']; $S2S_information = unserialize(stripslashes(urldecode($C2S_message))); if(isset($S2S_information->COMMAND) && isset($S2S_information->QUERY)) { $S2C_output = array(); $S2C_output = $VoCMySqlManager->Process($S2S_information->QUERY, $S2S_information->COMMAND); if($S2S_information->COMMAND) array_pop($S2C_output); echo urlencode(serialize($S2C_out...