Posts

Showing posts with the label PHP

Install XAMPP/LAMPP On Android (Non-Root)

Image
php apache setup on android with Termux (without root) Download Termux (allow installation from unknwon sources and install the termux app) Termux Setup Steps update packages (If it asks you, choose yes in both cases.) apt update -y && apt upgrade -y Install Apache and PHP 7 There is as of now a bundle that serves to introduce these two things together. That is, through apache PHP documents are prepared. To introduce our LAMPP on Android we will run: apt install php-apache That will install apache, PHP and a few libraries that will permit us to join the two things. configure apache to process the PHP files We are going to configure the httpd.conf file. Attention here, because the route is important. The apache configuration file is in /data/data/com.termux/files/usr/etc/apache2/httpd.conf You can change to that folder with: cd /data/ data /com.ter

Fix Uncaught Error Call to undefined function str_starts_with()

Image
Uncaught Error: Call to undefined function str_starts_with() Fix Solutions if (!function_exists('str_starts_with')) { function str_starts_with($haystack, $needle, $case = true) { if ($case) { return strpos($haystack, $needle, 0) === 0; } return stripos($haystack, $needle, 0) === 0; } } if (!function_exists('str_ends_with')) { function str_ends_with($haystack, $needle, $case = true) { $expectedPosition = strlen($haystack) - strlen($needle); if ($case) { return strrpos($haystack, $needle, 0) === $expectedPosition; } return strripos($haystack, $needle, 0) === $expectedPosition; } }

[PHP] Detect User Client IP (XAMPP or Localhost Machine Supported)

Usage: var_dump(get_client_ip()); /** * Detect is localhost * * @return boolean */ function isLocalHost() { $whitelist = [ '127.0.0.1', '::1', ]; return in_array($_SERVER['REMOTE_ADDR'], $whitelist); } /** * Get client ip, when getenv supported (maybe cli) * * @return string */ function get_client_ip() { $ipaddress = ''; if (isLocalHost()) { $ipaddress = getLocalIp(); } else { if (getenv('HTTP_CLIENT_IP')) { $ipaddress = getenv('HTTP_CLIENT_IP'); } elseif (getenv('HTTP_X_FORWARDED_FOR')) { $ipaddress = getenv('HTTP_X_FORWARDED_FOR'); } elseif (getenv('HTTP_X_FORWARDED')) { $ipaddress = getenv('HTTP_X_FORWARDED'); } elseif (getenv('HTTP_FORWARDED_FOR')) { $ipaddress = getenv('HTTP_FORWARDED_FOR'); } elseif (getenv('HTTP_FORWARDED')) { $ipaddress = getenv('HTTP_FORWARDED'); } elseif (ge

Calculate Swatch Internet Time Codes

PHP 12 bytes: <?php echo date('B'); ?> 48 bytes: <?php echo sprintf("%03d",((time()+3600)%86400)/86.4|0); ?> C,  56 bytes main(){printf("%03d",(int)((time(0)+3600)%86400/86.4));} Explanation: %03d  - tells printf to zero-pad up to 3 digits. time(NULL)+3600  - gets amount of seconds (UTC) elapsed since epoch and adds an hour to it (UTC+1). %86400  - divides epoch by the amount of seconds in a 24hr day and gets the remainder (representing seconds elapsed, so far, "today"). /86.4  - divide remaining seconds by 86.4 to get the ".beat" count since midnight (UTC+1). Compile (MSVC): C:> cl swatch.c Compile (GCC): $ gcc swatch.c Java 143 bytes import  java.time. * ; interface A  {   static void main(String[] a) {     System.out.format("%03.0f" ,  LocalTime.now(ZoneId.of("UT+1")).toSecondOfDay() / 86.4);    } } Javascript d=new Date();t=;console.log(Math.floor((360*d.getHours()+60*d.

PHP array magic trick and manipulations

manipulating multidimensional array using array_map /** * Ilterate multidimensional array simplicity * @desc modify and manipulate or populate multidimensional array with simple tricks * @param array $arr * @param function $callback * @return Array **/ function Map($arr, $callback) { if (!is_callable($callback)) { throw new Exception("Callback must be function", 1); } return array_map(function ($key, $val) use ($callback) { return call_user_func($callback, $key, $val); }, array_keys($arr), $arr); }

PHP Mailer work with AJAX

Image
Basic Mailer basic php mailer php <?php header('Access-Control-Allow-Origin: *'); header('Content-Type: application/json'); /* * CONFIGURE EVERYTHING HERE */ // an email address that will be in the From field of the email. $from = isset($_REQUEST['from']) ? $_REQUEST['from'] : 'example@mail.com'; $from = filter_var($from, FILTER_VALIDATE_EMAIL) ? $from : null; // an email address that will receive the email with the output of the form $sendTo = 'dimaslanjaka.superuser@blogger.com'; // subject of the email $subject = 'New message'; // form field names and their translations. // array variable name => Text to appear in the email $fields = array('name' => 'Name', 'surname' => 'Surname', 'phone' => 'Phone', 'email' => 'Email', 'message' => 'Message'); // message that will be displayed when everything is OK :) $okMess

Check if current function called statically or not

Image
$static = !(isset($this) && get_class($this) == __CLASS__); if ($static) { return self; } else { return $this; } in class example: class Foo { function bar() { $static = !(isset($this) && get_class($this) == __CLASS__); if ($static) { return self; } else { return $this; } } } or simply create below function to test: class A { function foo() { if (isset($this)) { echo '$this is defined ('; echo get_class($this); echo ")\n"; } else { echo "\$this is not defined.\n"; } } } How do I check in PHP that I'm in a static context (or not)?

Remove index.php?route= from opencart

Image
How to remove index.php?route= common issue from url bar for SEO url I Also have the same problem and any that I found not solved my problem. But! I remember that I also working with Laravel and in this engine well working url path. Don't ask why I associated OpenCart with Laravel. So I enable SEO radio button in System -> Settings -> Server you also can disable it I don't see difference in the site work. This solution consist from several part: 1. In your root folder replace .htaccess file content with next shapshot: <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews -Indexes </IfModule> RewriteEngine On # Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI}