CoolFace
Apppublic

CatPtain/wordpress

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
test-php.php146 linesDownload Raw Back to root
1<?php2/**3 * Simple PHP test file4 */5 6echo "<h1>PHP Test Page</h1>";7echo "<p>PHP Version: " . phpversion() . "</p>";8echo "<p>Current Time: " . date('Y-m-d H:i:s') . "</p>";9 10// Test SQLite11if (extension_loaded('pdo_sqlite')) {12    echo "<p style='color: green;'>✓ SQLite PDO extension is available</p>";13    14    try {15        $db_file = '/var/www/html/wp-content/database/wordpress.db';16        $pdo = new PDO('sqlite:' . $db_file);17        echo "<p style='color: green;'>✓ SQLite connection successful</p>";18        19        // Test a simple query20        $result = $pdo->query("SELECT name FROM sqlite_master WHERE type='table'");21        $tables = $result->fetchAll(PDO::FETCH_COLUMN);22        23        if (count($tables) > 0) {24            echo "<p>Database tables found: " . implode(', ', $tables) . "</p>";25        } else {26            echo "<p>No tables found in database (this is normal for a fresh install)</p>";27        }28        29    } catch (Exception $e) {30        echo "<p style='color: red;'>✗ SQLite connection failed: " . $e->getMessage() . "</p>";31    }32} else {33    echo "<p style='color: red;'>✗ SQLite PDO extension is NOT available</p>";34}35 36// Test file permissions37echo "<h2>File Permissions</h2>";38$files = [39    '/var/www/html/wp-config.php',40    '/var/www/html/wp-content/db.php',41    '/var/www/html/wp-content/database'42];43 44foreach ($files as $file) {45    if (file_exists($file)) {46        $perms = substr(sprintf('%o', fileperms($file)), -4);47        echo "<p>$file: $perms</p>";48    } else {49        echo "<p style='color: red;'>$file: NOT FOUND</p>";50    }51}52 53// Test WordPress database methods54echo "<h2>WordPress Database Methods Test</h2>";55if (file_exists('/var/www/html/wp-content/db.php')) {56    require_once('/var/www/html/wp-content/db.php');57    58    if (class_exists('SQLite_DB')) {59        $test_db = new SQLite_DB();60        61        echo "<p>✓ SQLite_DB class loaded successfully</p>";62        63        // Test required methods64        $methods = ['set_prefix', 'get_results', 'get_row', 'get_var', 'get_col', 'prepare', 'insert', 'update', 'delete', 'suppress_errors', 'show_errors', 'hide_errors', 'bail', 'timer_start', 'timer_stop', 'get_blog_prefix', '_escape', '_real_escape', '_weak_escape', 'escape', 'add_placeholder_escape', 'placeholder_escape'];65        foreach ($methods as $method) {66            if (method_exists($test_db, $method)) {67                echo "<p style='color: green;'>✓ Method $method exists</p>";68            } else {69                echo "<p style='color: red;'>✗ Method $method missing</p>";70            }71        }72        73        // Test properties74        $properties = ['prefix', 'posts', 'users', 'options', 'ready', 'field_types', 'suppress_errors', 'show_errors', 'time_start', 'blogid', 'base_prefix', 'charset', 'collate', 'dbname'];75        foreach ($properties as $prop) {76            if (property_exists($test_db, $prop)) {77                echo "<p style='color: green;'>✓ Property $prop exists</p>";78            } else {79                echo "<p style='color: red;'>✗ Property $prop missing</p>";80            }81        }82        83    } else {84        echo "<p style='color: red;'>✗ SQLite_DB class not found</p>";85    }86} else {87    echo "<p style='color: red;'>✗ wp-content/db.php not found</p>";88}89 90// Test database connection91echo "<h3>Database Connection Test</h3>";92if ($db->ready) {93    echo "<p style='color: green;'>✓ Database connection successful</p>";94    echo "<p>Database type: SQLite (in-memory)</p>";95    echo "<p>Database prefix: " . $db->prefix . "</p>";96    97    // Test if WordPress tables were created98    echo "<h4>WordPress Tables Test</h4>";99    $tables_to_check = array('posts', 'users', 'options', 'comments', 'terms', 'term_taxonomy', 'term_relationships');100    foreach ($tables_to_check as $table) {101        $table_name = $db->prefix . $table;102        $result = $db->get_results("SELECT name FROM sqlite_master WHERE type='table' AND name='$table_name'");103        if (!empty($result)) {104            echo "<p style='color: green;'>✓ Table '$table_name' exists</p>";105        } else {106            echo "<p style='color: red;'>✗ Table '$table_name' missing</p>";107        }108    }109    110    // Test default options111    echo "<h4>Default Options Test</h4>";112    $option_count = $db->get_var("SELECT COUNT(*) FROM {$db->prefix}options");113    echo "<p>Total options in database: $option_count</p>";114    115    $test_options = array('siteurl', 'home', 'blogname', 'blogdescription', 'users_can_register', 'admin_email');116    foreach ($test_options as $option) {117        $value = $db->get_var($db->prepare("SELECT option_value FROM {$db->prefix}options WHERE option_name = %s", $option));118        if ($value !== null) {119            echo "<p style='color: green;'>✓ Option '$option': $value</p>";120        } else {121            echo "<p style='color: red;'>✗ Option '$option' not found</p>";122        }123    }124    125    echo "<h3>Escape Methods Test</h3>";126    // Test escape methods127    $test_string = "Test's \"quoted\" string with % symbols";128    $test_array = array('key1' => "value's", 'key2' => 'value"with"quotes');129    130    echo "<p><strong>Original string:</strong> " . htmlspecialchars($test_string) . "</p>";131    echo "<p><strong>_escape():</strong> " . htmlspecialchars($db->_escape($test_string)) . "</p>";132    echo "<p><strong>_real_escape():</strong> " . htmlspecialchars($db->_real_escape($test_string)) . "</p>";133    echo "<p><strong>_weak_escape():</strong> " . htmlspecialchars($db->_weak_escape($test_string)) . "</p>";134    135    echo "<p><strong>Array escape test:</strong></p>";136    $escaped_array = $db->_escape($test_array);137    foreach ($escaped_array as $key => $value) {138        echo "<p style='margin-left: 20px;'>$key: " . htmlspecialchars($value) . "</p>";139    }140} else {141    echo "<p style='color: red;'>✗ Database connection failed</p>";142}143 144echo "<hr>";145echo "<p><a href='/'>Try WordPress</a> | <a href='/debug.php'>Debug Info</a></p>";146?>