Skip to content

Instantly share code, notes, and snippets.

View thagxt's full-sized avatar
🎯
Focusing

ʞↃ∀ɾ thagxt

🎯
Focusing
View GitHub Profile
@thagxt
thagxt / mage2-multiweb-subdir.md
Last active April 24, 2024 09:19
Set up Magento 2 multiple websites in sub directories

Set up Magento 2 multiple websites in sub directories

  1. Go to Admin > Stores > All Stores
  2. Click > Create Web Site
  3. In the Name field, enter store name.
    • e.g. Japan
  4. In the Code field, enter a unique string without spaces and > Save Web Site
    • e.g. super_jp
  5. Create Store
  6. Create Store View
@thagxt
thagxt / check-if-valid-url.php
Last active March 20, 2024 08:00
check if url is valid
<?php
/* @ http://stackoverflow.com/a/12628971 */
function isValidUrl($url){
// first do some quick sanity checks:
if(!$url || !is_string($url)){
return false;
}
// quick check url is roughly a valid http request: ( http://blah/... )
if( ! preg_match('/^http(s)?:\/\/[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(\/.*)?$/i', $url) ){
return false;
@thagxt
thagxt / downunzip.php
Created January 17, 2015 13:20
Easiest way to download & extract zip files from a remote server to yours.
<?php
/*
1) upload this file into the folder you'd like to extract the content of the downloaded .zip file.
2) run the script in you browser. i.e. http://localhost/downunzip.php
3) after the script was executed sucesfully, login thru ftp and remove this script
*/
/* you can change this */
$download_url = "https://wordpress.org/latest.zip"; // url to zip file you want to download
$delete = "no"; // if you DO NOT want the .zip file to be deleted after it was extracted set "yes" to "no".
@thagxt
thagxt / login.php
Created February 18, 2016 17:11
simple PHP login without a database
<?php
session_start();
// ***************************************** //
// ********** DECLARE VARIABLES ********** //
// ***************************************** //
$username = 'username';
$password = 'password';
@thagxt
thagxt / functions.php
Created January 31, 2015 15:51
[WordPress] Change the wp-login.php?action=lostpassword to /lost-password/
/*
* code below goes in your functions.php theme file.
*/
// changing the wp-login.php?action=lostpassword to /lost-password/
function custom_lost_password_page() {
return home_url('/lost-password/');
}
add_filter('lostpassword_url', 'custom_lost_password_page');
@thagxt
thagxt / run-a-local-server-inside-dir.md
Last active December 2, 2022 16:48
Run a local web server inside any folder on Mac, Window, Linux, PHP, Node.js

Node.js

# Install http-server module globally 
npm install http-server -g

# Navigate to any directory you want the server to run in
cd /path/to/dir/with/files

# Launch HTTP server
@thagxt
thagxt / Add a custom url in the Wordprss Admin bar.php
Last active September 18, 2022 20:42
Add a custom url in the Wordprss Admin bar!
<?php // copy & paste the code below in your functions.php file, change the title and href and save it.
function add_link_to_adminbar($wp_admin_bar){
$args = array(
'id' => 'custom-link',
'title' => 'Custom Button Title',
'href' => 'http://example.org/',
'meta' => array(
'class' => 'custom-link-class'
@thagxt
thagxt / url-check.php
Last active September 7, 2022 17:39
Check if URL exists in PHP - With this function you can check if a URL is really 404 or else
<?php
// With this function you can check response code if it really is 404 or nah
function isValidUrl($url){
// first do some quick sanity checks:
if(!$url || !is_string($url)){
return false;
}
// quick check url is roughly a valid http request: ( http://blah/... )
if( ! preg_match('/^http(s)?:\/\/[a-z0-9-]+(\.[a-z0-9-]+)*(:[0-9]+)?(\/.*)?$/i', $url) ){
@thagxt
thagxt / dl-ex.php
Last active February 23, 2022 18:45
Download & Extract .zip with cURL directly on your server
<?php
$url = "https://wordpress.org/latest.zip"; // URL of what you wan to download
$zipFile = "wordpress.zip"; // Rename .zip file
$extractDir = "extracted"; // Name of the directory where files are extracted
$zipResource = fopen($zipFile, "w");
// Get The Zip File From Server
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);

Forcing HTTPS Redirection and Cloudflare’s Flexible SSL

If you force http to https redirection on your website, while using CloudFlare, with the following normal methods, a loop redirection occurs.

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

Normal Redirect via PHP