Skip to content

Instantly share code, notes, and snippets.

@alvissqn
alvissqn / dumprequest.php
Created February 27, 2023 02:31 — forked from magnetikonline/dumprequest.php
PHP script to dump full HTTP request to file (method, HTTP headers and body).
<?php
// https://gist.github.com/magnetikonline/650e30e485c0f91f2f40
class DumpHTTPRequestToFile {
public function execute($targetFile) {
$data = sprintf(
"%s %s %s\n\nHTTP headers:\n",
$_SERVER['REQUEST_METHOD'],
$_SERVER['REQUEST_URI'],
$_SERVER['SERVER_PROTOCOL']
@alvissqn
alvissqn / file_get_contents_curl.php
Created February 27, 2023 01:52 — forked from tuytoosh/file_get_contents_curl.php
php file_get_contents() with curl
<?php
function file_get_contents_curl( $url ) {
$ch = curl_init();
curl_setopt( $ch, CURLOPT_AUTOREFERER, TRUE );
curl_setopt( $ch, CURLOPT_HEADER, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_URL, $url );
@alvissqn
alvissqn / functions.php
Created April 4, 2021 18:09 — forked from vishalbasnet23/functions.php
User Registration Front End WordPress with Ajax
<?php
add_action('wp_ajax_register_user_front_end', 'register_user_front_end', 0);
add_action('wp_ajax_nopriv_register_user_front_end', 'register_user_front_end');
function register_user_front_end() {
$new_user_name = stripcslashes($_POST['new_user_name']);
$new_user_email = stripcslashes($_POST['new_user_email']);
$new_user_password = $_POST['new_user_password'];
$user_nice_name = strtolower($_POST['new_user_email']);
$user_data = array(
'user_login' => $new_user_name,
@alvissqn
alvissqn / function.php
Created December 19, 2020 02:16 — forked from mattclements/function.php
Wordpress Disable Comments (add to function.php)
<?php
add_action('admin_init', function () {
// Redirect any user trying to access comments page
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_redirect(admin_url());
exit;
}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-utf-8">
</head>
<body>
<?php
print "<h1></h1>\n";
echo "Your Ip: ";
echo $_SERVER['REMOTE_ADDR'];
echo "<form method=\"post\" enctype=\"multipart/form-data\">\n";
@alvissqn
alvissqn / gist:cacb196cd7d6b1c111243d2e9d4e4e77
Last active April 29, 2024 10:42
Một số code trong wordpress
Xóa Widgets ở Dashboard Wordpress
/------------------------\
//Remove Dashboard Metabox Widgets for all users except Admin
add_action('wp_dashboard_setup', 'stsd_remove_dashboard_widget' );
function stsd_remove_dashboard_widget() {
if (!current_user_can('manage_options')){
global $wp_meta_boxes;
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
@echo off
set /p domain="Enter Domain: "
set OPENSSL_CONF=../conf/openssl.cnf
if not exist .\%domain% mkdir .\%domain%
..\bin\openssl req -config cert.conf -new -sha256 -newkey rsa:2048 -nodes -keyout %domain%\server.key -x509 -days 365 -out %domain%\server.crt
echo.
echo -----
[ req ]
default_bits = 2048
default_keyfile = server-key.pem
distinguished_name = subject
req_extensions = req_ext
x509_extensions = x509_ext
string_mask = utf8only
[ subject ]
--- Tạo Slug bằng php -----
<?php
function convert_vi_to_en($str) {
$str = preg_replace(“/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/”, ‘a’, $str);
$str = preg_replace(“/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/”, ‘e’, $str);
$str = preg_replace(“/(ì|í|ị|ỉ|ĩ)/”, ‘i’, $str);
$str = preg_replace(“/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/”, ‘o’, $str);
$str = preg_replace(“/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/”, ‘u’, $str);
$str = preg_replace(“/(ỳ|ý|ỵ|ỷ|ỹ)/”, ‘y’, $str);
$str = preg_replace(“/(đ)/”, ‘d’, $str);
@alvissqn
alvissqn / short-number-format.php
Created March 11, 2018 19:11 — forked from RadGH/short-number-format.php
Short Number Formatter for PHP (1000 to 1k; 1m; 1b; 1t)
<?php
// Converts a number into a short version, eg: 1000 -> 1k
// Based on: http://stackoverflow.com/a/4371114
function number_format_short( $n, $precision = 1 ) {
if ($n < 900) {
// 0 - 900
$n_format = number_format($n, $precision);
$suffix = '';
} else if ($n < 900000) {