about.anekakebutuhan ADMIN/INDEX.PHP
<?php
define ( "_QUIXPLORER_PATH", dirname(__FILE__) );
// define ( "_QUIXPLORER_URL", "http://localhost/TinyWebGallery/admin" );
define ( "_QUIXPLORER_URL", "." );
This code defines two PHP constants used to tell the application where it is installed and how to build URLs to itself.
The first line, define("_QUIXPLORER_PATH", dirname(__FILE__));, creates a constant named _QUIXPLORER_PATH and assigns it the directory path of the current file. In PHP, FILE contains the full path to the script being executed, and dirname(FILE) strips off the filename, leaving only the folder path. This is commonly used to reference local resources like templates, uploads, or configuration files without hardcoding a server-specific absolute path.
The second line is commented out, so it is not active. It shows an alternative definition for _QUIXPLORER_URL using an absolute URL: http://localhost/TinyWebGallery/admin. That would be useful in a local development setup where the app is served from a fixed URL. The next active line, define("_QUIXPLORER_URL", ".");, instead sets the URL to a relative path: a single dot, which means “the current directory.” This is a portable setting that works when the application is accessed from a relative location, such as a local folder or a site root that is not always known in advance.
Together, these constants separate the filesystem location from the browser-visible URL. _QUIXPLORER_PATH is used for server-side file access, while _QUIXPLORER_URL is used for generating links or redirecting users in the browser. Using "." makes the app less dependent on a specific host or server path, which is often convenient for development, deployment portability, or when the app is installed in a subdirectory.
<?php
global $action;
In PHP, the statement global $action; tells the current scope to use the global variable named $action instead of a local variable with the same name. By default, variables inside a function are local to that function, so if you want to access or change a variable that was created outside the function, you must declare it as global.
In this project, $action is likely used to decide what operation the script should perform, such as listing files, uploading files, deleting items, or editing a file. You can see that pattern in the file where it later does a switch($action) and branches based on the value of $action. That means the code depends on a variable set elsewhere, and this line ensures that variable is available in the current function scope.
This is a common older PHP pattern, but it is also one of the main sources of bugs because it creates hidden dependencies on global state. In modern PHP, it is usually better to pass values as parameters or use request data such as $_GET or $_POST directly instead of relying on global variables.
<?php
umask(0002);
This line sets the process file-creation mask to 0002. In PHP, umask() controls the default permissions that newly created files and directories receive. The value passed in is the mask, and it is subtracted from the default permission set rather than directly applied as final permissions.
The value 0002 means: when a new file or directory is created, the group-write bit is allowed. In Unix-like systems, the default permission for files is often 666 and for directories 777. The umask removes bits from that default. With 0002, the world-write bit is blocked, but group-write is preserved, which is a common choice for shared development environments where multiple users in the same group need write access to files. This is why the code comment says it is “Added to make created files/dirs group writable.”
The purpose here is to avoid permissions that are too restrictive for collaborative use. For example, without this, newly created files might be created with permissions like 644, which are not writable by the group. With umask(0002), the result is typically more permissive for group members, making it easier for team members or server processes sharing the same group to work with generated files and folders.
<?php
ob_start();
This line turns on output buffering in PHP. When you call ob_start(), PHP does not immediately send output to the browser or client. Instead, it stores the generated output in an internal buffer first. This is useful when you want to delay output until the script is ready, modify it, or ensure that headers are sent before any content is emitted.
In this project, the code is likely using buffering before loading configuration and application logic. That can be helpful because some scripts need to set cookies, send headers, or perform redirects before content is flushed. If output were sent too early, those operations could fail or produce warnings. By buffering the output, the application can safely process everything and then flush the buffer at the proper time.
A common pattern is: - start buffering with ob_start() - do application work - optionally modify or clean the output - end buffering with ob_end_clean() or ob_flush()
The comment in the file says ob_start(); // cleaned in init!, which suggests the buffer is intentionally created and later cleaned up during initialization. That means the script may temporarily hold output so it can be sanitized or reset before final rendering. This is a common technique in older PHP codebases to avoid accidental output before the framework finishes initializing.
<?php
require_once realpath(_QUIXPLORER_PATH . "/../inc/filefunctions.inc.php");
This line loads another PHP file only once, using a path built from the application’s root directory. The function require_once tells PHP to include the file and stop with a fatal error if it cannot be found. The important part is the argument: _QUIXPLORER_PATH . "/../inc/filefunctions.inc.php". Here, _QUIXPLORER_PATH is the directory of the current script, defined earlier as the folder containing index.php. By appending "/../inc/filefunctions.inc.php", it points to a file in the parent directory’s inc folder, which is where shared helper functions are stored.
The call to realpath() converts that relative path into a canonical absolute path before including it. This is useful because it avoids path problems caused by different working directories or symbolic links. In other words, PHP is being told: “take this application folder, go up one level, open inc/filefunctions.inc.php, and include it exactly once.” That file likely contains utility functions such as file operations, validation helpers, or shared logic used throughout the app. Using require_once is important here so the same file is not accidentally included multiple times, which could cause redeclaration errors or duplicate function definitions.
<?php
checkXSS();
checkXSS(); is a function call that likely runs a custom security check before the rest of the script continues. In web applications, XSS stands for Cross-Site Scripting, which is a common attack where malicious script code is injected through user input and then executed in a visitor’s browser. A function like this is usually meant to inspect inputs, headers, or request parameters and block or sanitize dangerous content before it can be displayed or stored.
In this file manager codebase, it is probably called early in the request lifecycle to protect the application from malicious data coming from the browser, such as crafted URLs, form submissions, or uploaded content. The exact behavior depends on how the function is defined elsewhere, but the name strongly suggests it checks whether any request data contains script tags, JavaScript, or other unsafe patterns. This is a good example of a defensive security step: it does not “fix” the app by itself, but it reduces the risk of malicious input causing HTML injection or script execution.
<?php
require realpath((dirname(__FILE__) . "/../config.php"));
This line loads a PHP configuration file from the parent directory of the current script. The expression dirname(FILE) gets the directory containing the current file, and adding "/../config.php" moves up one level to the project’s root or parent folder, then targets a file named config.php. The realpath() call resolves that path to a full absolute path before it is included, which helps avoid issues caused by different working directories or relative path problems.
The require statement then includes that file as PHP code. If the file cannot be found or cannot be loaded, PHP stops execution with a fatal error. In a web application, this is usually where database credentials, application settings, and global configuration values are defined. So this line is essentially “load the app configuration from the parent folder before continuing with the rest of the script.”
<?php
if (isset($try_to_increase_memory_limit_to_32MB)) {
if ($try_to_increase_memory_limit_to_32MB) {
@ini_set('memory_limit', '32M');
}
}
This block is a guarded configuration check. It first asks whether a variable named $try_to_increase_memory_limit_to_32MB exists by using isset(). If that variable is present, it enters the outer if. Then it checks the value of the same variable in the inner if. The pattern is effectively: “if the feature flag is enabled, then do the action.”
When the flag is true, the code calls ini_set('memory_limit', '32M');. This tells PHP to raise the memory limit for the current script to 32 megabytes. This is useful in older PHP applications or file-processing scripts that may need more memory than the default server limit allows. The value 32M is a string, which is the format PHP expects for ini settings.
The @ before ini_set() suppresses warnings or errors from PHP if the setting cannot be changed, such as when the server restricts runtime configuration or the environment does not allow memory limit changes. This makes the code more tolerant in shared hosting or restricted server environments. The overall effect is: “only try to increase memory if the developer explicitly enabled that option, and don’t crash the app if the system refuses.”
<?php
if (function_exists('date_default_timezone_set')) { // php 5.1.x
if ($timezone != '') {
@date_default_timezone_set($timezone);
} else if (function_exists('date_default_timezone_get')) {
set_error_handler('on_error_no_output');
@date_default_timezone_set(@date_default_timezone_get());
set_error_handler('on_error');
} else {
@date_default_timezone_set('Europe/Berlin');
}
}
This block configures the PHP timezone for the current script. It starts by checking whether the function date_default_timezone_set exists, which means the server is running a PHP version that supports timezone configuration. If it does, the code then decides how to set the timezone.
Inside, it first checks whether a variable named $timezone is not empty. If it has a value, it calls date_default_timezone_set($timezone) to use that timezone directly. If $timezone is empty, it tries to detect the server’s default timezone automatically using date_default_timezone_get(). Before doing that, it temporarily replaces the error handler with on_error_no_output, then calls the timezone setter and restores the original handler afterward. This prevents warning messages from leaking to the browser when the environment has no valid timezone configured. If neither a custom timezone nor an automatic one is available, it falls back to Europe/Berlin as a default.
The @ symbol before the timezone-setting calls suppresses PHP warnings, which is useful because timezone detection or configuration can fail on some hosting environments. This code is defensive: it tries to honor a configured timezone, auto-detect one if possible, and otherwise choose a safe default so date and time functions behave consistently throughout the application.
enter code here
This code does two things: it initializes a variable and then includes the application’s startup file. The first line, $install_dir = "";, sets a variable named $install_dir to an empty string. This is a placeholder value, and it is often used to indicate that the installation directory is not yet known or that the application should compute it dynamically. In many PHP apps, this kind of variable is used to help build paths or detect where files are being served from.
The second line, include _QUIXPLORER_PATH . "/_include/init.php";, loads another PHP file from the project’s defined base directory. _QUIXPLORER_PATH is a constant created earlier, and it points to the folder where this script lives. By appending "/_include/init.php", the code builds a full path to the initialization file inside a subfolder named _include. The include statement executes that file as part of the current script, so all of its definitions, functions, and configuration are available afterward.
This pattern is common in app bootstrapping: a script sets up basic variables, then includes the central initialization logic that configures the application. It keeps the entry point simple while delegating the heavy setup work to a dedicated file.
<?php
$dir = $GLOBALS["dir"];
$item = $GLOBALS["item"];
$cachedir = '../' . $cachedir;
These three lines read values from PHP’s global scope and assign them to local variables. $GLOBALS is a special superglobal array that contains all variables defined in global scope, including values that may have been set elsewhere in the application before this code runs. In other words, $GLOBALS["dir"] and $GLOBALS["item"] are being copied into the variables $dir and $item so they can be used more conveniently in the current script or function. This is a common pattern in older PHP code, especially when a script is using a framework or bootstrap file that populates values globally.
The first two assignments are simple aliases: $dir gets the value of the global variable named dir, and $item gets the value of the global variable named item. This makes the code easier to read and reduces repeated use of $GLOBALS[...] throughout the file. It also helps when the script expects local variables for processing, such as selecting a directory or an item to work with.
The third line, $cachedir = '../' . $cachedir;, builds a relative path for the cache directory by prepending ../ to whatever value is already stored in $cachedir. This is often done to move from a script’s current folder to a parent directory, such as from an admin folder back to the site root or a cache folder. The result is a path like ../cache or ../tmp, depending on the original value. This kind of relative path is useful when the application is installed in a subdirectory and must reference files or folders from a parent location.
<?php
switch($action) { // Execute action
//------------------------------------------------------------------------------
// EDIT FILE
case "edit":
require _QUIXPLORER_PATH . "/_include/fun_edit.php";
edit_file($dir, $item);
break;
This block is a request router. It checks the value of the $action variable and chooses what code to run based on that value. The switch statement is a clean way to handle multiple possible actions in one place, instead of writing a long chain of if/else conditions. In this code, the action is likely set from a query string, form submission, or global variable earlier in the script, and the application uses it to decide which operation to perform.
The case "edit": branch matches when $action equals the string "edit". When that happens, the script includes the file _QUIXPLORER_PATH . "/_include/fun_edit.php". That file likely contains the logic for editing a file and all of its helper functions. After loading it, the code calls edit_file($dir, $item);, passing in the current directory and file name. The $dir and $item variables were retrieved earlier from the global state, so the editing function knows exactly which file should be edited.
The break; statement ends the current case. Without it, PHP would continue executing the following cases, which is usually not wanted. This pattern is common in admin panels or file managers: the user performs an action, the script reads $action, and the matching case loads the relevant logic and executes it.
jadi fungsi switch($action) { ... )
sebenarnya perintah eksekusi sebuah parameter atau subset parameter ?
Saya jelaskan maksudnya dalam konteks file ini, supaya jelas apakah switch($action) itu “mengeksekusi parameter” atau “mengambil keputusan berdasarkan nilai parameter.”
Jawaban
switch($action) bukan perintah eksekusi parameter itu sendiri, melainkan struktur kontrol untuk mengevaluasi nilai dari variabel $action lalu memilih blok kode yang sesuai.
Artinya:
$actionadalah parameter atau nilai yang dikirim dari luar, misalnya dari URL, form, atau variabel global.switch($action)membandingkan isi$actiondengan beberapacase.- Jika nilainya cocok dengan salah satu
case, maka blok kode di bawahnya akan dijalankan.
Contoh dari file ini:
switch($action) {
case "edit":
require _QUIXPLORER_PATH . "/_include/fun_edit.php";
edit_file($dir, $item);
break;
case "delete":
require _QUIXPLORER_PATH . "/_include/fun_del.php";
del_items($dir);
break;
case "list":
default:
require _QUIXPLORER_PATH . "/_include/fun_list.php";
list_dir($GLOBALS["dir"]);
break;
}
Jadi logikanya seperti ini:
- kalau
$action == "edit"→ jalankan fungsi edit - kalau
$action == "delete"→ jalankan fungsi delete - kalau
$actiontidak cocok dengan case apa pun → jalankan default, biasanya list
Jadi, apakah ini “eksekusi parameter”?
Bukan secara langsung. Lebih tepatnya:
switch($action)adalah “pengambil keputusan”case "edit"dancase "delete"adalah “subset/opsi dari parameter”- lalu blok kode di dalamnya adalah “eksekusi yang sesuai”
Jadi bisa dibilang:
switch($action)adalah mekanisme untuk mengeksekusi aksi tertentu berdasarkan nilai parameter$action.
Kalau mau, saya juga bisa jelaskan perbedaan antara switch, if/else, dan case dalam konteks skrip ini dengan contoh yang lebih sederhana.
ya, mau
agar lebih jelas saja
Ilustrasi sederhana
Bayangkan ini seperti menu pilihan:
$action = "edit";
Lalu program membaca:
switch($action) {
case "edit":
echo "Buka halaman edit";
break;
case "delete":
echo "Hapus file";
break;
default:
echo "Tampilkan daftar";
}
Hasilnya:
$actionadalah nilai yang masukswitch($action)adalah “cek nilai ini”case "edit"adalah “kalau nilainya edit, lakukan ini”defaultadalah “kalau tidak cocok semua, lakukan ini”
Dalam konteks file ini
Di file admin/index.php, $action kemungkinan datang dari URL, form, atau variabel global. Kemudian kode ini:
switch($action) {
berarti:
“Tentukan apa yang harus dilakukan berdasarkan aksi yang diminta.”
Misalnya:
action=edit→ jalankan logika editaction=delete→ jalankan logika deleteaction=upload→ jalankan logika upload- kalau tidak ada aksi yang cocok → jalankan default yaitu list
Jadi singkatnya
switch($action) bukan “mengeksekusi parameter” secara langsung.
Lebih tepatnya:
$action= nilai parameterswitch($action)= pemeriksaan nilaicase ...= pilihan yang sesuai- blok di dalam
case= eksekusi yang benar
Jadi fungsi utamanya adalah:
memilih dan menjalankan kode sesuai dengan nilai parameter
$action.
Kalau mau, saya juga bisa buatkan versi yang lebih teknis tapi tetap sederhana: “bagaimana switch($action) berhubungan dengan URL query seperti ?action=edit”.
ya, buatkan versi lebih teknis
Versi teknis
switch($action) adalah struktur kontrol yang mengevaluasi isi variabel $action dan memetakan nilai tersebut ke blok kode yang sesuai. Ini adalah alternatif dari beberapa if ... elseif ... else yang lebih panjang.
Dalam konteks ini, $action berfungsi sebagai dispatcher atau router untuk menentukan operasi yang akan dijalankan oleh file manager. Nilai $action biasanya berasal dari input HTTP, seperti query string, form POST, atau variabel global yang diinisialisasi sebelumnya.
Contoh bentuk umum:
switch ($action) {
case "edit":
// jalankan fungsi edit
break;
case "delete":
// jalankan fungsi delete
break;
case "upload":
// jalankan fungsi upload
break;
default:
// jalankan mode default
break;
}
Dalam file yang Anda tunjuk, masing-masing case memuat file handler tertentu dan memanggil fungsi yang relevan, misalnya:
case "edit"→ memanggiledit_file($dir, $item)case "delete"→ memanggildel_items($dir)case "upload"→ memanggilupload_items($dir)case "list"ataudefault→ menampilkan daftar direktori
Secara teknis, ini adalah pattern dispatcher:
- input:
$action - proses: evaluasi nilai
- output: pemanggilan handler yang sesuai
Jadi, switch($action) bukan “parameter itu sendiri” dalam arti eksekusi, melainkan mekanisme routing yang memutuskan blok eksekusi berdasarkan nilai parameter tersebut.
Dengan kata lain,
$actionadalah kondisi/identitas operasi, sedangkanswitch($action)adalah mesin pengarah yang memilih fungsi yang tepat untuk dijalankan.
Kalau mau, saya juga bisa lanjutkan dengan versi yang menjelaskan hubungan switch($action) dengan $_GET['action'] atau $_REQUEST['action'] dalam PHP.
<?php
show_twg_footer();
show_footer();
close_tags();
These three function calls are most likely the final stage of the page rendering process. They are called at the end of the script after the main logic has already run, which usually means the application has finished preparing the page content and is now outputting the closing HTML structure. The first call, show_twg_footer(), probably renders the footer for this specific web application or plugin, while show_footer() may be a more generic footer function used by the broader site or framework. In many PHP apps, these kinds of functions generate the bottom section of the page, such as copyright text, menu links, or script tags.
The last call, close_tags(), suggests that the script is closing any HTML or markup elements that were opened earlier during the page setup. This often includes tags like body, html, or any wrappers created during layout generation. In other words, these calls are part of the cleanup and presentation phase: the page content is generated, the application-specific and generic footers are inserted, and then the markup is finalized so the browser can render the page correctly.
This is a common pattern in simple PHP applications and custom admin panels. It separates the main logic from the final output stage, making the code easier to follow and maintain. The script handles the data and actions first, then finishes by rendering the footer and closing the document structure.
artinya 3 perintah fungsi terakhir terkait dengan case yang terpilih/dipilih.
Jadi akan mengacu ke APAPUN sebagai output terkait masing-masing CASE ?
I will explain how those last three calls fit into the selected switch case logic, so you can see whether they are generic finalizers or specific outputs for each case.
Benar, tapi ada nuance penting:
switch($action)menentukan case yang dipilih.- Setelah case itu dijalankan, baris kode berikutnya akan tetap dijalankan jika letaknya setelah
switchdan tidak berada di dalam case tertentu. - Jadi
show_twg_footer(); show_footer(); close_tags();biasanya bukan “output khusus case”, melainkan “kode penutup halaman” yang dipanggil setelah semua logika utama selesai.
Jadi kalau struktur seperti ini:
switch ($action) {
case "edit":
edit_file($dir, $item);
break;
case "delete":
delete_file($dir, $item);
break;
}
show_twg_footer();
show_footer();
close_tags();
maka:
case "edit"ataucase "delete"memilih aksi tertentu- lalu setelah
switchselesai, fungsi footer dan close_tags tetap dipanggil - artinya, output footer/penutup halaman itu umum untuk semua case, bukan hanya satu case tertentu
Kalau ingin lebih spesifik per case, biasanya mereka diletakkan di dalam masing-masing case, misalnya:
case "edit":
edit_file($dir, $item);
show_twg_footer();
show_footer();
close_tags();
break;
Nah, itu baru “terkait dengan case tertentu”.
Jadi jawabannya:
- Jika
show_twg_footer(); show_footer(); close_tags();berada di luarswitch, maka ya, itu akan berlaku untuk APAPUN case yang dipilih. - Jika berada di dalam
case "edit"saja, maka hanya untuk case edit. - Jika di dalam beberapa case tertentu, maka hanya untuk case itu saja.
Secara logika, fungsi terakhir ini biasanya lebih mirip “finalizer halaman” daripada “handler aksi”, jadi sering dipanggil setelah semua case selesai. Inilah yang paling umum dalam script seperti ini.
bagaimana saya melacak ke 3 fungsi ini berasal darimana atau ada dimana ?
I’ll show you the quickest reliable ways to trace where those three functions are defined and how to follow them in this PHP project.
Cara paling cepat adalah dengan mengikuti jejak fungsi seperti ini:
- Cari definisi langsung
- Di VS Code, klik kanan pada nama fungsi lalu pilih:
- Go to Definition
- Peek Definition
- Find All References
- Atau tekan:
- F12
- Ctrl+Click
- Untuk fungsi ini:
- show_twg_footer
- show_footer
- close_tags
- Gunakan pencarian teks
- Tekan Ctrl+Shift+F
- Cari salah satu nama fungsi:
- show_twg_footer
- show_footer
- close_tags
- Kalau perlu, pakai regex:
- show_twg_footer|show_footer|close_tags
- Cek file yang di-include sebelumnya Di file index.php, kemungkinan fungsi-fungsi itu tidak didefinisikan di sini, tetapi di file yang dimasukkan sebelumnya, misalnya:
- require_once .../filefunctions.inc.php
- include _QUIXPLORER_PATH . "/_include/init.php";
- file lain di folder _include, inc, lib, atau functions
Jadi langkah yang umum: - lihat file yang di-include sebelum pemanggilan fungsi - cari definisi fungsi di file-file itu
- Cek apakah fungsi berasal dari library/global
Kadang fungsi seperti
show_footer()bisa datang dari:
- file konfigurasi aplikasi - helper class - file framework - file umum yang disertakan dari parent directory
- Kalau tidak ketemu dalam workspace Mungkin fungsi itu:
- ada di library eksternal - di file yang tidak masuk workspace - dipanggil via autoload / class method / namespace
Contoh kalau ada namespace:
\MyApp\Template::show_footer();
atau
$this->show_footer();
Maka pencarian nama saja bisa tidak cukup; perlu lihat konteks pemanggilan.
Metode paling aman: - cari nama fungsi - lalu buka file definisi - lalu lihat file yang memanggilnya - lalu lihat include/require chain di index.php
Contoh alur:
include _QUIXPLORER_PATH . "/_include/init.php";
...
show_twg_footer();
show_footer();
close_tags();
Artinya kemungkinan definisinya bukan di index.php, tapi di file _include/init.php atau file lain yang di-load dari sana.
Kalau Anda mau, saya bisa bantu langkah-langkah yang lebih spesifik untuk file ini, misalnya:
- “cara cari definisi show_footer di project ini”
- atau “cara menelusuri include chain dari index.php sampai fungsi definisinya”
cara menelusuri include chain dari index.php sampai fungsi definisinya
I’ll give you a practical tracing routine you can use in VS Code to follow the include chain from this index.php to the actual function definitions.
Ini cara paling praktis untuk menelusuri include chain dari index.php sampai ke definisi fungsi.
- Mulai dari file index.php Buka file index.php.
Lihat baris yang memuat file lain, misalnya:
require_once realpath(_QUIXPLORER_PATH . "/../inc/filefunctions.inc.php");
include _QUIXPLORER_PATH . "/_include/init.php";
require realpath((dirname(__FILE__) . "/../config.php"));
Ini adalah titik masuk utama untuk tracing.
- Cek semua file yang di-include Yang paling penting adalah file-file ini:
- ../inc/filefunctions.inc.php
- _include/init.php
- ../config.php
Buat urutan pencarian seperti ini:
- buka satu file
- cari include, require, require_once, include_once
- ulangi untuk setiap file baru yang ditemukan
- teruskan sampai tidak ada file baru lagi
- Di VS Code, gunakan “Go to Definition” Misalnya:
- klik show_twg_footer()
- tekan F12 atau Ctrl+Click
- kalau fungsi itu ada di file lain, VS Code akan membuka definisinya
Kalau tidak bisa, berarti: - fungsi itu didefinisikan di file yang belum ter-include - fungsi itu berasal dari library / framework - fungsi itu boleh jadi global helper
- Gunakan pencarian multi-file Tekan:
- Ctrl+Shift+F
- lalu cari nama fungsi:
- show_twg_footer
- show_footer
- close_tags
Hasil pencarian akan menunjukkan: - lokasi pemanggilan - lokasi definisi - file yang mungkin memuat helper tersebut
- Buat diagram sederhana Biasanya alurnya seperti ini:
admin/index.php
-> include _include/init.php
-> include helper files
-> define show_twg_footer()
-> define show_footer()
-> define close_tags()
Atau bisa juga:
index.php
-> config.php
-> filefunctions.inc.php
-> init.php
-> include footer.php
-> function show_footer()
- Gunakan strategi “follow the includes” Ini routine yang paling efektif:
- cari
include/requiredi index.php - buka file yang paling relevan
- cari lagi di file itu
- ulangi
- setiap kali menemukan
function ...atauclass ..., itu biasanya definisi target
- Kalau fungsi tidak ditemukan Lakukan pengecekan berikut:
- apakah fungsi itu global dari PHP framework?
- apakah ada namespace?
- apakah ada autoload?
- apakah fungsi itu dipanggil sebelum definisinya dibuat?
- apakah dibuat dalam file yang tidak ikut workspace?
Contoh kemungkinan:
function show_footer() {
...
}
atau
class Template {
public function show_footer() {
...
}
}
Kalau mau, saya bisa bantu Anda membuat “include chain” yang konkret dari file index.php ini berdasarkan pola umum script file manager/TWG, lalu tunjukkan lokasi yang paling mungkin untuk show_twg_footer(), show_footer(), dan close_tags().
bantu buatkan “include chain” yang konkret dari file terkait index.php ini
Saya akan menelusuri file-file yang di-include dari index.php dan menyusun rantai include yang paling mungkin terjadi di project ini.
Searching for regex include|require (**/admin/**)
Searched for regex include|require_once|require (**/admin/**/*.php), 202 results
Searching for regex function\s+show_twg_footer|function\s+show_footer|function\s+close_tags (**/*.php)
Searched for text show_twg_footer (**/admin/**/*.php), 4 results
Searched for text show_footer (**/admin/**/*.php), 4 results
Searched for text close_tags (**/admin/**/*.php), 4 results
Include chain konkret dari index.php
Berdasarkan trace yang ada di index.php, rantai include-nya kira-kira seperti ini:
admin/index.php
├─ require_once ../inc/filefunctions.inc.php
├─ require ../config.php
└─ include _include/init.php
├─ require _config/conf.php
├─ require _lang/*.php
├─ require _config/mimes.php
├─ require _include/fun_extra.php
├─ require _include/header.php
├─ require _include/footer.php
├─ require _include/error.php
└─ require menu.php
Jadi fungsi yang dipanggil di akhir file:
show_twg_footer()show_footer()close_tags()
bukan didefinisikan di index.php, melainkan didapat dari file yang di-include sebelumnya.
Lokasi definisi fungsi
Saya menemukan definisi aktualnya di:
footer.php
show_footer()show_twg_footer()
fun_extra.php
close_tags()
Ini sesuai dengan yang tertulis di init.php, yang secara jelas melakukan include ke file-file tersebut:
require _QUIXPLORER_PATH . "/_include/fun_extra.php";
require _QUIXPLORER_PATH . "/_include/header.php";
require _QUIXPLORER_PATH . "/_include/footer.php";
require _QUIXPLORER_PATH . "/_include/error.php";
require _QUIXPLORER_PATH . "/menu.php";
Jadi kesimpulannya
Rangkaian yang konkret adalah:
admin/index.php
-> include admin/_include/init.php
-> require admin/_include/footer.php
-> function show_twg_footer()
-> function show_footer()
-> require admin/_include/fun_extra.php
-> function close_tags()
Maka saat di akhir index.php ada:
show_twg_footer();
show_footer();
close_tags();
itu artinya PHP sedang memanggil fungsi yang sudah didefinisikan di file-file yang tadi di-include.
Kalau Anda mau, saya bisa lanjutkan dengan versi diagram yang lebih visual seperti “call graph” satu layar, atau buatkan cara menelusuri ini secara manual di VS Code step by step.
buatkan cara menelusuri ini secara manual di VS Code step by step.
Saya akan rangkum langkah-langkah manual yang paling praktis di VS Code untuk mengikuti include chain dari index.php sampai definisi fungsi.
Cara manual menelusuri include chain di VS Code
Ini cara paling straightforward untuk melacak dari index.php sampai fungsi yang dipanggil.
1. Mulai dari file utama
Buka index.php.
Cari baris yang meng-include file lain, seperti:
require_once realpath(_QUIXPLORER_PATH . "/../inc/filefunctions.inc.php");
require realpath((dirname(__FILE__) . "/../config.php"));
include _QUIXPLORER_PATH . "/_include/init.php";
Itu adalah “root” dari tracing.
2. Buka file yang paling penting dulu
Buka init.php.
Di sana Anda akan melihat baris seperti:
require _QUIXPLORER_PATH . "/_config/conf.php";
require _QUIXPLORER_PATH . "/_include/fun_extra.php";
require _QUIXPLORER_PATH . "/_include/header.php";
require _QUIXPLORER_PATH . "/_include/footer.php";
require _QUIXPLORER_PATH . "/_include/error.php";
require _QUIXPLORER_PATH . "/menu.php";
Ini adalah titik yang paling penting, karena fungsi yang dipanggil di akhir index.php muncul di sini.
3. Cari definisi fungsi yang dipanggil
Sekarang cari nama fungsi yang ada di akhir file:
show_twg_footershow_footerclose_tags
Di VS Code, lakukan salah satu cara berikut:
- Klik nama fungsi lalu tekan F12
- Klik kanan => Go to Definition
- Klik kanan => Find All References
Contoh:
- klik show_twg_footer
- tekan F12
- VS Code akan membuka file tempat definisinya
Pada project ini, definisinya ada di: - footer.php - fun_extra.php
4. Cek apakah fungsi memang berasal dari include
Setelah Anda membuka footer.php, cari:
function show_footer() { ... }
function show_twg_footer() { ... }
Maka Anda akan melihat jelas bahwa fungsi ini bukan didefinisikan di index.php, melainkan di file yang di-include dari init.php.
Lakukan hal yang sama untuk close_tags() di fun_extra.php.
5. Buka file lain yang dibutuhkan
Jika Anda ingin terus menelusuri lebih dalam, lakukan langkah yang sama:
- buka file yang di-include
- cari
includeataurequirelagi - ulangi
- terus cari definisi fungsi yang dicall
Jadi alurnya seperti: - file utama → include file A → include file B → definisi fungsi di file C
6. Gunakan pencarian global di workspace
Kalau definisi tidak langsung terbuka dari F12, gunakan pencarian:
- tekan Ctrl+Shift+F
- cari
show_twg_footer - cari
show_footer - cari
close_tags
VS Code akan menampilkan: - tempat pemanggilan - tempat definisi - file-file yang terkait
7. Teknik paling aman: trace top-down
Gunakan pola ini:
- buka file awal
- lihat semua
include/require - buka file include pertama
- ulangi sampai menemukan
function ... - catat jalur trace
Contoh log trace untuk project ini:
admin/index.php
-> include admin/_include/init.php
-> require admin/_include/footer.php
-> function show_twg_footer()
-> function show_footer()
-> require admin/_include/fun_extra.php
-> function close_tags()
8. Penjelasan singkat logika
Jadi untuk fungsi di akhir file:
show_twg_footer();
show_footer();
close_tags();
artinya:
- PHP memanggil fungsi yang sudah didefinisikan sebelumnya
- fungsi tersebut bukan ada di file yang sedang dibuka
- tetapi sudah masuk ke memori karena file includenya sudah dipanggil sebelumnya
Ini adalah pola umum dalam PHP lama: file utama mengumpulkan helper dan fungsi dari file-file include, lalu menjalankannya dari satu titik.
Kalau Anda mau, saya bisa lanjutkan dengan:
- versi tracing yang lebih detail per baris untuk file ini, atau
- cara yang sama tapi untuk file lain yang termasuk switch($action) dan case "edit", case "delete", dll.
buatkan cara menelusuri ini secara manual di VS Code step by step.
Saya akan rangkum langkah-langkah manual yang paling praktis di VS Code untuk mengikuti include chain dari index.php sampai definisi fungsi.
Cara manual menelusuri include chain di VS Code
Ini cara paling straightforward untuk melacak dari index.php sampai fungsi yang dipanggil.
1. Mulai dari file utama
Buka index.php.
Cari baris yang meng-include file lain, seperti:
require_once realpath(_QUIXPLORER_PATH . "/../inc/filefunctions.inc.php");
require realpath((dirname(__FILE__) . "/../config.php"));
include _QUIXPLORER_PATH . "/_include/init.php";
Itu adalah “root” dari tracing.
2. Buka file yang paling penting dulu
Buka init.php.
Di sana Anda akan melihat baris seperti:
require _QUIXPLORER_PATH . "/_config/conf.php";
require _QUIXPLORER_PATH . "/_include/fun_extra.php";
require _QUIXPLORER_PATH . "/_include/header.php";
require _QUIXPLORER_PATH . "/_include/footer.php";
require _QUIXPLORER_PATH . "/_include/error.php";
require _QUIXPLORER_PATH . "/menu.php";
Ini adalah titik yang paling penting, karena fungsi yang dipanggil di akhir index.php muncul di sini.
3. Cari definisi fungsi yang dipanggil
Sekarang cari nama fungsi yang ada di akhir file:
show_twg_footershow_footerclose_tags
Di VS Code, lakukan salah satu cara berikut:
- Klik nama fungsi lalu tekan F12
- Klik kanan => Go to Definition
- Klik kanan => Find All References
Contoh:
- klik show_twg_footer
- tekan F12
- VS Code akan membuka file tempat definisinya
Pada project ini, definisinya ada di: - footer.php - fun_extra.php
4. Cek apakah fungsi memang berasal dari include
Setelah Anda membuka footer.php, cari:
function show_footer() { ... }
function show_twg_footer() { ... }
Maka Anda akan melihat jelas bahwa fungsi ini bukan didefinisikan di index.php, melainkan di file yang di-include dari init.php.
Lakukan hal yang sama untuk close_tags() di fun_extra.php.
5. Buka file lain yang dibutuhkan
Jika Anda ingin terus menelusuri lebih dalam, lakukan langkah yang sama:
- buka file yang di-include
- cari
includeataurequirelagi - ulangi
- terus cari definisi fungsi yang dicall
Jadi alurnya seperti: - file utama → include file A → include file B → definisi fungsi di file C
6. Gunakan pencarian global di workspace
Kalau definisi tidak langsung terbuka dari F12, gunakan pencarian:
- tekan Ctrl+Shift+F
- cari
show_twg_footer - cari
show_footer - cari
close_tags
VS Code akan menampilkan: - tempat pemanggilan - tempat definisi - file-file yang terkait
7. Teknik paling aman: trace top-down
Gunakan pola ini:
- buka file awal
- lihat semua
include/require - buka file include pertama
- ulangi sampai menemukan
function ... - catat jalur trace
Contoh log trace untuk project ini:
admin/index.php
-> include admin/_include/init.php
-> require admin/_include/footer.php
-> function show_twg_footer()
-> function show_footer()
-> require admin/_include/fun_extra.php
-> function close_tags()
8. Penjelasan singkat logika
Jadi untuk fungsi di akhir file:
show_twg_footer();
show_footer();
close_tags();
artinya:
- PHP memanggil fungsi yang sudah didefinisikan sebelumnya
- fungsi tersebut bukan ada di file yang sedang dibuka
- tetapi sudah masuk ke memori karena file includenya sudah dipanggil sebelumnya
Ini adalah pola umum dalam PHP lama: file utama mengumpulkan helper dan fungsi dari file-file include, lalu menjalankannya dari satu titik.
Kalau Anda mau, saya bisa lanjutkan dengan:
- versi tracing yang lebih detail per baris untuk file ini, atau
- cara yang sama tapi untuk file lain yang termasuk switch($action) dan case "edit", case "delete", dll.
cara yang sama tapi untuk file lain yang termasuk `switch($action)` dan `case "edit"`, `case "delete"`, dll.
Saya akan tunjukkan pola yang sama untuk melacak file lain yang juga memakai switch($action) dan case "edit", case "delete", dsb.## Pola tracing yang sama untuk file lain
Untuk file lain yang punya struktur seperti ini:
switch($action) {
case "edit":
...
break;
case "delete":
...
break;
case "upload":
...
break;
}
cara tracing-nya tetap sama, hanya fokus pada 3 hal:
- cari variabel
$action - cari
switch($action) - cari
case "edit",case "delete", dll.
1. Cari switch($action)
Buka file yang akan ditrace, lalu cari:
switch($action)
Biasanya ini akan muncul dekat bagian akhir file, sebelum output akhir.
2. Lihat isi setiap case
Setiap case biasanya seperti ini:
case "edit":
require ...;
edit_file(...);
break;
case "delete":
require ...;
del_items(...);
break;
Artinya:
case "edit"= aksi editcase "delete"= aksi deletecase "upload"= aksi uploadcase "list"ataudefault= mode default
3. Ikuti file yang dipanggil di case
Misalnya:
case "edit":
require _QUIXPLORER_PATH . "/_include/fun_edit.php";
edit_file($dir, $item);
break;
Maka langkah berikutnya:
- buka file fun_edit.php
- cari fungsi
edit_file - lihat isinya untuk mengetahui proses edit sebenarnya
Contoh trace:
file utama
-> switch($action)
-> case "edit"
-> require _include/fun_edit.php
-> function edit_file()
Lakukan hal yang sama untuk:
- delete → file fun_del.php
- upload → file fun_up.php
- copy/move → file fun_copy_move.php
- rename → file fun_rename.php
- download → file fun_down.php
4. Gunakan F12 pada nama fungsi di case
Misalnya:
- klik
edit_file - tekan F12
- buka file tempat definisi fungsi
Atau:
- klik
del_items - tekan F12
- buka file tempat definisi fungsi
Ini cara paling cepat untuk melacak sampai fungsi yang benar-benar menjalankan logika utama.
5. Cek file include sebelum switch
Kadang file utama juga melakukan include file helper sebelum switch, misalnya:
require_once .../filefunctions.inc.php;
include .../init.php;
Maka fungsi yang dipanggil di case mungkin didefinisikan di file helper tersebut, bukan di file utama.
Jadi trace yang lengkap biasanya seperti:
file utama
-> include helper
-> switch($action)
-> case "edit"
-> require file handler
-> function edit_file()
6. Pola manual yang umum
Ini pola yang bisa Anda pakai untuk file apa pun yang punya switch($action):
1. Cari switch($action)
2. Baca semua case
3. Untuk setiap case:
- lihat file yang di-include
- cari fungsi yang dipanggil
- buka definisi fungsi
4. Lanjutkan tracing di file handler itu
7. Contoh konkret dari project ini
Dalam index.php, case-nya seperti:
edit→ fun_edit.phpdelete→ fun_del.phpcopy/move→ fun_copy_move.phprename→ fun_rename.phpdownload→ fun_down.phpupload→ fun_up.phplist/default→ fun_list.php
Jadi trace untuk satu case misalnya edit adalah:
admin/index.php
-> switch($action)
-> case "edit"
-> require admin/_include/fun_edit.php
-> function edit_file(...)
Kalau Anda mau, saya bisa bantu lanjutkan dengan:
- membuat trace lengkap untuk case "edit" dan case "delete"
- atau menyiapkan template “cara trace switch-case” yang bisa dipakai untuk file PHP lain di project Anda.
pada awal eksekusi skrip, baris :
global $action;
mencatat apa ? nilai acak atau ?
global $action; bukan mencatat nilai acak. Itu hanya memberitahu PHP:
“Gunakan variabel
$actiondari scope global, bukan variabel lokal yang baru dibuat di fungsi.”
Jadi ia tidak membuat nilai baru, dan juga bukan menyimpan nilai acak. Ia hanya menghubungkan variabel lokal/siap pakai dengan variabel global yang sudah ada di memori.
Dalam konteks file ini
Variabel $action kemungkinan sudah dibuat sebelumnya oleh:
- URL parameter, misalnya ?action=edit
- form submission
- file konfigurasi
- script lain yang sudah menjalankan bagian awal aplikasi
- atau bahkan dibuat di file lain yang di-include sebelumnya
Jadi alurnya kira-kira:
// di file lain / script lain
$action = "edit";
Lalu di file ini:
global $action;
PHP berkata: “oke, pakai variabel global $action yang sama itu, bukan variabel baru”.
Kalau belum ada nilainya?
Jika $action belum pernah dibuat sebelumnya, maka global $action; tidak akan membuat nilai acak. Ia hanya mengakses variabel global yang mungkin belum didefinisikan. Jika belum ada, biasanya nilainya akan dianggap NULL atau tidak ada.
Jadi:
global $action;= bukan “mencatat nilai”global $action;= “ambil variabel global yang sudah ada”
Jadi jawabannya:
- bukan nilai acak
- bukan deklarasi nilai
- hanya referensi ke variabel global yang sudah ada di ruang global PHP
Lalu setelah itu, switch($action) akan memeriksa isinya. Misalnya kalau nilainya "edit", maka blok case "edit": yang akan dijalankan.
Contoh:
$action = "delete";
switch ($action) {
case "edit":
echo "edit";
break;
case "delete":
echo "delete";
break;
}
Outputnya adalah delete.
Jadi pengertian yang tepat adalah:
global $action;tidak mencatat nilai baru, tetapi “mengaitkan” variabel yang ada di scope global supaya bisa dipakai di scope saat ini.
Kalau mau, saya bisa lanjutkan dengan contoh konkret hubungan global $action; dengan ?action=edit atau dengan form POST.
maksudnya terkait ini ?
define( '_VALID_TWG', '42' );
$GLOBALS['tx_version'] = '1.0';
$GLOBALS['tx_home'] = 'http://about.parmi.web.id';
define ( "_QUIXPLORER_PATH", dirname(__FILE__) );
// define ( "_QUIXPLORER_URL", "http://localhost/TinyWebGallery/admin" );
define ( "_QUIXPLORER_URL", "." );
global $action;
$action mencatat semua defini sebelumnya ?
Tidak. Yang ini bukan berarti $action “mencatat semua definisi sebelumnya”.
Yang terjadi adalah:
define(...)membuat konstanta, misalnya_VALID_TWG,_QUIXPLORER_PATH,_QUIXPLORER_URL$GLOBALS['tx_version']dan$GLOBALS['tx_home']menyimpan data ke array globalglobal $action;hanya mengakses variabel global bernama$actionyang mungkin sudah ada di scope global
Jadi, $action tidak otomatis terisi oleh definisi sebelumnya seperti:
define( '_VALID_TWG', '42' );
$GLOBALS['tx_version'] = '1.0';
$GLOBALS['tx_home'] = 'http://about.parmi.web.id';
Nilai-nilai itu adalah variabel/konstanta yang berbeda.
Bedanya:
define(...)→ konstanta$GLOBALS[...]→ variabel globalglobal $action;→ mengakses variabel$actionglobal yang sudah ada
Mereka tidak saling terkait secara otomatis.
Jadi, $action itu biasanya diisi dari mana?
Biasanya dari input luar, misalnya:
- URL: ?action=edit
- form: $_POST['action']
- variabel global yang dibuat di file lain
- atau hasil dari file yang di-include sebelumnya
Contoh umum:
$action = $_GET['action'] ?? 'list';
atau
global $action;
lalu switch($action) akan memutuskan:
- edit
- delete
- upload
- list
- dll
Jadi jawaban singkat:
global $action; tidak mencatat semua definisi sebelumnya.
Ia hanya menghubungkan variabel global $action yang mungkin sudah ada, supaya bisa dipakai di script ini. Nilai $action itu sendiri datang dari luar atau dari script lain, bukan dari:
define( '_VALID_TWG', '42' );
$GLOBALS['tx_version'] = '1.0';
$GLOBALS['tx_home'] = 'http://about.parmi.web.id';
Kalau Anda mau, saya bisa lanjutkan dengan contoh konkret: “bagaimana $action biasanya diisi dari URL seperti ?action=edit lalu dipakai di switch($action)”.
lanjutkan dengan contoh konkret: “bagaimana $action biasanya diisi dari URL seperti ?action=edit lalu dipakai di switch($action)”
Contoh konkret: $action dari URL lalu dipakai di switch($action)
Dalam PHP, variabel $action sering diisi dari query string di URL, misalnya:
?action=edit
atau
?action=delete
Contoh kode:
<?php
$action = $_GET['action'] ?? 'list';
switch($action) {
case "edit":
echo "Mode edit aktif";
break;
case "delete":
echo "Mode delete aktif";
break;
case "upload":
echo "Mode upload aktif";
break;
default:
echo "Mode list/default aktif";
break;
}
Kalau URL-nya seperti ini:
http://example.com/admin/index.php?action=edit
maka:
$action = $_GET['action'] ?? 'list';
akan menghasilkan:
$action = "edit";
Lalu switch($action) akan cocok dengan:
case "edit":
dan menjalankan kode di dalamnya.
Dalam konteks project Anda
Di file index.php, baris yang relevan adalah:
global $action;
yang artinya script ini mengharapkan bahwa $action sudah ada di scope global, biasanya dari input seperti URL atau request lainnya.
Lalu di bawahnya ada:
switch($action) {
case "edit":
require _QUIXPLORER_PATH . "/_include/fun_edit.php";
edit_file($dir, $item);
break;
Artinya:
- kalau $action bernilai "edit", jalankan edit
- kalau "delete", jalankan delete
- kalau "upload", jalankan upload
- kalau tidak cocok, pakai default list
Contoh yang mirip dengan project ini
Misalnya URL-nya:
http://about.parmi.web.id/admin/index.php?action=delete&item=file.txt
Maka biasanya satu bagian lain dari aplikasi menangkap parameter seperti ini:
$action = $_GET['action'];
$item = $_GET['item'];
Lalu:
switch($action) {
case "delete":
del_items($dir);
break;
}
Jadi keputusan eksekusi benar-benar bergantung pada nilai yang datang dari URL atau form.
Kesimpulan
$action biasanya diisi oleh parameter request, dan switch($action) adalah “router” yang memutuskan fungsi mana yang harus dijalankan.
Jadi bukan dari definisi seperti:
define( '_VALID_TWG', '42' );
atau
$GLOBALS['tx_version'] = '1.0';
melainkan dari input request yang datang ke script.
Kalau Anda mau, saya bisa lanjutkan dengan contoh yang sangat mirip dengan project ini: “dari URL ?action=edit sampai masuk ke case "edit": dan memanggil fun_edit.php”.
lanjutkan dengan contoh yang sangat mirip dengan project ini: “dari URL `?action=edit` sampai masuk ke `case "edit":` dan memanggil fun_edit.php”.
Contoh yang sangat mirip dengan project ini
Bayangkan URL seperti ini:
http://about.parmi.web.id/admin/index.php?action=edit&item=artikel.txt
Lalu scriptnya seperti ini:
<?php
global $action;
global $item;
$action = $_GET['action'] ?? 'list';
$item = $_GET['item'] ?? '';
switch($action) {
case "edit":
require "admin/_include/fun_edit.php";
edit_file($dir, $item);
break;
case "delete":
require "admin/_include/fun_del.php";
del_items($dir);
break;
default:
require "admin/_include/fun_list.php";
list_dir($dir);
break;
}
?>
Urutannya:
Browser mengirim URL:
?action=edit&item=artikel.txtPHP membaca parameter:
$action = $_GET['action'] ?? 'list';Hasilnya:
$action = "edit";Lalu masuk ke:
switch($action)Karena nilainya
"edit", maka masuk ke:case "edit":Di dalam case itu:
require "admin/_include/fun_edit.php"; edit_file($dir, $item);File fun_edit.php di-include, lalu fungsi
edit_file()dipanggil.
Sama seperti project Anda
Di file index.php, struktur yang mirip adalah:
switch($action) {
case "edit":
require _QUIXPLORER_PATH . "/_include/fun_edit.php";
edit_file($dir, $item);
break;
}
Yang berarti:
- jika
$actionbernilai"edit" - maka file fun_edit.php dimasukkan
- lalu fungsi
edit_file($dir, $item)dijalankan - dan
$dirserta$itemsudah disiapkan sebelumnya dari variabel global
Jadi alur lengkapnya
URL: ?action=edit&item=file.txt
-> $_GET['action'] = "edit"
-> $action = "edit"
-> switch($action)
-> case "edit"
-> require fun_edit.php
-> edit_file($dir, $item)
Itu adalah hubungan yang benar antara URL, variabel $action, dan switch($action).
Kalau Anda mau, saya bisa lanjutkan dengan contoh yang sama untuk case "delete" dan case "list" agar semua case terlihat jelas.
lanjutkan dengan contoh yang sama untuk `case "delete"` dan `case "list"` agar semua case terlihat jelas.
Contoh lengkap untuk case "delete" dan case "list"
Berikut contoh yang sangat mirip pola project Anda.
1. case "delete"
URL:
http://about.parmi.web.id/admin/index.php?action=delete&item=file.txt
Kode:
<?php
$action = $_GET['action'] ?? 'list';
$item = $_GET['item'] ?? '';
switch($action) {
case "delete":
require "admin/_include/fun_del.php";
del_items($dir);
break;
default:
require "admin/_include/fun_list.php";
list_dir($dir);
break;
}
?>
Alur:
?action=delete
-> $action = "delete"
-> switch($action)
-> case "delete"
-> require fun_del.php
-> del_items($dir)
Artinya, file fun_del.php akan di-include, lalu fungsi del_items($dir) akan dipanggil untuk menghapus item.
2. case "list" atau default
URL:
http://about.parmi.web.id/admin/index.php?action=list
atau kalau tidak ada parameter action:
http://about.parmi.web.id/admin/index.php
Kode:
<?php
$action = $_GET['action'] ?? 'list';
switch($action) {
case "edit":
require "admin/_include/fun_edit.php";
edit_file($dir, $item);
break;
case "delete":
require "admin/_include/fun_del.php";
del_items($dir);
break;
case "list":
default:
require "admin/_include/fun_list.php";
list_dir($dir);
break;
}
?>
Alur:
?action=list
-> $action = "list"
-> switch($action)
-> case "list"
-> require fun_list.php
-> list_dir($dir)
Kalau tidak ada action, maka default-nya yang dipakai. Dalam project Anda, ini terlihat jelas di akhir switch:
case "list":
default:
require _QUIXPLORER_PATH . "/_include/fun_list.php";
list_dir($GLOBALS["dir"]);
Kesimpulan pola yang sama
Semua case bekerja dengan cara yang sama:
URL parameter -> $action -> switch($action) -> case yang cocok -> include file handler -> panggil fungsi handler
Jadi untuk project Anda:
?action=edit→case "edit"→ include fun_edit.php?action=delete→case "delete"→ include fun_del.php?action=listatau tidak ada action →case "list"/default→ include fun_list.php
Kalau Anda mau, saya bisa lanjutkan dengan versi diagram alur lengkap untuk seluruh case yang ada di index.php, mulai dari URL sampai ke fungsi masing-masing.
anjutkan dengan versi diagram alur lengkap untuk seluruh case yang ada di index.php, mulai dari URL sampai ke fungsi masing-masing.
Diagram alur lengkap untuk seluruh case pada index.php
Berikut alur yang paling cocok dengan pola kode di index.php:
Browser / URL
|
| ?action=edit
| ?action=delete
| ?action=upload
| ?action=download
| ?action=rename
| ?action=copy
| ?action=move
| ?action=help
| ?action=info
| ... dll
v
PHP request parameter
|
| $action = $_GET['action'] atau $_POST['action'] atau variabel global
v
switch($action)
|
+--> case "edit"
| |
| -> require admin/_include/fun_edit.php
| -> edit_file($dir, $item)
|
+--> case "delete"
| |
| -> require admin/_include/fun_del.php
| -> del_items($dir)
|
+--> case "copy"
| case "move"
| |
| -> require admin/_include/fun_copy_move.php
| -> copy_move_items($dir)
|
+--> case "rename"
| |
| -> require admin/_include/fun_rename.php
| -> rename_item($dir, $item)
|
+--> case "download"
| |
| -> require admin/_include/fun_down.php
| -> download_item($dir, $item)
|
+--> case "upload"
| |
| -> require admin/_include/fun_up.php
| -> upload_items($dir)
|
+--> case "storecss"
| |
| -> require admin/_include/twg_storecss.php
| -> return
|
+--> case "mkitem"
| |
| -> require admin/_include/fun_mkitem.php
| -> make_item($dir)
|
+--> case "chmod"
| |
| -> require admin/_include/fun_chmod.php
| -> chmod_item($dir, $GLOBALS["item"])
|
+--> case "search"
| |
| -> require admin/_include/fun_search.php
| -> search_items($dir)
|
+--> case "arch"
| |
| -> require admin/_include/fun_archive.php
| -> archive_items($dir)
|
+--> case "extract"
| |
| -> require admin/_include/fun_archive.php
| -> extract_item($dir, $item)
|
+--> case "admin"
| |
| -> require admin/_include/fun_admin.php
| -> show_admin($dir)
|
+--> case "info"
| |
| -> require admin/info.php
| -> show_menu()
|
+--> case "colorpicker"
| |
| -> require admin/colorpicker.php
| -> show_menu()
|
+--> case "helper"
| |
| -> require admin/helper.php
| -> show_menu() / helper logic
|
+--> case "helper_gen"
| |
| -> require admin/helper_gen.php
| -> exit()
|
+--> case "help"
| |
| -> require admin/help.php
| -> show_menu()
|
+--> case "email"
| |
| -> require admin/email_admin.php
| -> show_menu()
|
+--> case "ajax"
| |
| -> require admin/_include/twg_ajax.php
| -> setAjaxParameters()
|
+--> case "list":
| default:
| |
| -> $_SESSION['twg_admin_logged_in'] = "true";
| -> show_menu();
| -> require admin/_include/fun_list.php
| -> list_dir($GLOBALS["dir"])
|
v
show_twg_footer();
show_footer();
close_tags();
Versi yang lebih ringkas
URL ?action=...
-> $action
-> switch($action)
-> case X
-> include file handler
-> call function handler
Contoh:
?action=edit
-> $action = "edit"
-> case "edit"
-> require fun_edit.php
-> edit_file($dir, $item)
atau:
?action=delete
-> $action = "delete"
-> case "delete"
-> require fun_del.php
-> del_items($dir)
atau:
?action=list
-> $action = "list"
-> case "list"
-> require fun_list.php
-> list_dir($dir)
Inti dari struktur ini
Semua case di index.php adalah router aksi:
- URL menentukan aksi
$actionmenampung nilai aksiswitch($action)memilih case- case memanggil file handler dan fungsi tertentu
Itulah pola dasar “action dispatcher” yang sering dipakai pada admin panel atau file manager.
Kalau mau, saya bisa lanjutkan dengan langkah khusus:
- “bagaimana trace dari ?action=edit sampai fun_edit.php di project ini”
- atau “diagram alur yang lebih visual seperti flowchart untuk semua case”
saya punya contoh PHP soal iniL
<?php
$x = 5;
function add($y) {
global $x;
return $x + $y;
}
echo "$x + 5 is " . add(5);
?>
sedangkan di index.php saya tak di beri nilai sebelumnya. Sedangkan index.php adalah skrip awal sekali diakses
bagaimana memunculkan $action agar bisa diketahui, apa nilai awalnya ?
Intinya
Dalam contoh PHP Anda:
$x = 5;
function add($y) {
global $x;
return $x + $y;
}
variabel $x diisi dulu sebelum fungsi dipanggil. Jadi di dalam fungsi, global $x; hanya “mengakses” variabel global yang sudah ada.
Kalau di index.php tidak ada nilai yang sebelumnya di-set untuk $action, maka:
$actionbelum punya nilai- atau nilainya
NULL - atau tidak ada di scope global
- lalu
switch($action)bisa berperilaku tidak stabil atau masuk ke default kalau memang ada default
Dalam aplikasi web, $action biasanya diisi dari request
Cara yang umum adalah:
<?php
$action = $_GET['action'] ?? 'list';
atau
<?php
$action = $_POST['action'] ?? 'list';
atau
<?php
$action = $_REQUEST['action'] ?? 'list';
Kalau URL-nya:
index.php?action=edit
maka $action menjadi:
"edit"
Lalu switch akan menjalankan case edit:
switch($action) {
case "edit":
echo "edit mode";
break;
default:
echo "list mode";
break;
}
Di file Anda yang awal diakses
Di index.php, kita tidak melihat:
$action = $_GET['action'] ?? 'list';
atau
$action = $_POST['action'] ?? 'list';
Jadi kemungkinan besar:
$actiondiisi dari file lain sebelum switch- atau dari bootstrapping / framework / include sebelumnya
- atau memang belum di-set, lalu aplikasi mengandalkan default /
list
Karena di file ini switch($action) ada di bawah, maka harus ada sesuatu yang mengisi $action sebelumnya, entah:
- $_GET['action']
- $_POST['action']
- global dari file lain
- atau nilai default yang dibuat di file bootstrap
Cara paling aman untuk mengetahui nilai awalnya
Coba tambahkan debug sementara:
<?php
var_dump($action);
atau
<?php
var_dump($_GET['action'] ?? 'tidak ada');
Kalau mau langsung cek status di awal skrip:
<?php
echo "action = ";
var_dump($action ?? null);
atau
<?php
if (!isset($action)) {
echo "action belum di-set";
} else {
echo "action = " . $action;
}
Yang penting: nilai awalnya bukan “acak”
Nilai awal $action jika tidak di-set adalah:
- NULL, atau
- tidak ada variabel
- dan switch($action) biasanya akan masuk ke default jika ada default case
Dalam index.php, ada default case:
case "list":
default:
...
Artinya kalau $action tidak cocok dengan case lain, otomatis akan masuk ke list.
Kesimpulan
Untuk file awal yang diakses:
global $action;saja tidak menciptakan nilai$actionharus diisi dulu, biasanya dari request URL atau file lain- kalau tidak di-set, nilainya biasanya
NULL - dalam aplikasi ini kemungkinan default ke mode
"list"
Kalau Anda mau, saya bisa bantu lanjutkan dengan versi yang lebih konkret, misalnya:
- “cara men-debug $action di index.php”
- atau “cara menambah echo $action; di awal file agar terlihat nilainya”
cara menambah `echo $action;` di awal file agar terlihat nilainya
lalu skrip pause sebelum di klik lanjut
Cara menambahkan debug untuk melihat nilai $action
Letakkan ini di awal file, setelah baris global $action; atau bahkan sebelum switch($action):
global $action;
echo "DEBUG action = ";
var_dump($action);
echo "<br>";
Kalau ingin lebih sederhana:
global $action;
echo "Nilai action: " . var_export($action, true) . "<br>";
atau:
global $action;
if (!isset($action)) {
echo "action belum di-set<br>";
} else {
echo "action = " . $action . "<br>";
}
Jadi di file Anda, bisa jadi seperti ini:
define ( "_QUIXPLORER_PATH", dirname(__FILE__) );
define ( "_QUIXPLORER_URL", "." );
global $action;
echo "DEBUG action = ";
var_dump($action);
echo "<br>";
Agar skrip “pause” sebelum lanjut
Kalau Anda ingin berhenti sementara agar bisa melihat output, ada beberapa cara.
Cara paling sederhana
Gunakan exit; setelah debug:
global $action;
var_dump($action);
exit;
Dengan ini, skrip berhenti tepat di sana, jadi Anda bisa melihat nilai $action di browser.
Cara untuk menahan eksekusi di browser
Misalnya:
global $action;
echo "<pre>";
var_dump($action);
echo "</pre>";
exit;
Ini akan menampilkan nilai dan berhenti.
Kalau Anda mau lihat output lalu lanjut
Bisa pakai:
global $action;
echo "<pre>";
var_dump($action);
echo "</pre>";
sleep(10); // hanya kalau server mengizinkan
Tapi sleep(10) bukan cara yang bagus untuk debugging di web, karena browser akan menunggu 10 detik.
Cara yang paling praktis adalah:
var_dump($action);
exit;
Contoh yang paling cocok untuk file Anda Coba tempel ini sebelum switch($action):
<?php
global $action;
echo "<pre>DEBUG action = ";
var_dump($action);
echo "</pre>";
exit;
Artinya:
- halaman akan menampilkan nilai $action
- lalu berhenti di titik itu
- Anda bisa langsung melihat parameternya
Catatan penting
Kalau $action memang belum di-set, hasilnya biasanya:
NULL
dan jika Anda melihat NULL, berarti memang harus diisi dari:
- URL: ?action=edit
- form POST
- atau file lain sebelum switch
Kalau Anda mau, saya bisa bantu menulis versi debug yang langsung cocok dimasukkan ke index.php tanpa mengganggu file terlalu banyak.
ajaib, satupun skrip skrip di atas tidak berfungsi. hasil browser tak terpengaruh
Kemungkinan paling besar: browser tidak menjalankan PHP sama sekali
Kalau semua echo, var_dump, atau exit “tidak berpengaruh”, maka kemungkinan besar yang terjadi adalah:
- file yang dibuka bukan file PHP yang benar-benar diproses oleh PHP Engine
- atau browser membuka file sebagai file statis, bukan melalui server web
- atau ada cache/URL yang salah
- atau server web belum menjalankan PHP untuk folder ini
Yang harus dipastikan
1. Buka lewat server web, bukan file lokal
Kalau Anda membuka seperti ini:
file:///U:/about.parmi.web.id/admin/index.php
maka browser hanya membaca file teks, bukan menjalankan PHP.
Harus lewat URL seperti:
http://localhost/.../admin/index.php
atau
http://127.0.0.1/.../admin/index.php
2. Pastikan PHP aktif di server
Server harus punya: - Apache / nginx - PHP module / PHP-FPM - file ini dipetakan ke interpreter PHP
Kalau tidak, browser akan menampilkan kode sumber PHP seperti teks biasa.
3. Cek apakah output masih disembunyikan
Di index.php ada ini:
ob_start();
yang artinya output ditahan di buffer. Jadi kalau Anda menaruh echo atau var_dump sebelum buffer dibersihkan/ditutup, kemungkinan output tidak terlihat sampai nanti. Artinya browser bisa “terlihat kosong” walau debug sudah dilakukan.
Jadi untuk debug, lebih aman lakukan:
ob_end_clean();
var_dump($action);
exit;
atau bisa juga menempatkan debug di titik yang paling awal sebelum output yang lain.
Coba cara paling sederhana
Tempatkan ini di paling atas file index.php, sebelum semua include:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
global $action;
var_dump($action);
exit;
Jika browser masih kosong, itu artinya: - file tidak diproses PHP - atau URL yang dibuka salah - atau server tidak memproses PHP untuk folder ini
Langkah paling pasti
Coba jalankan dari terminal:
php -v
Kalau PHP tidak terinstall atau tidak bisa keluar versi, berarti masalah bukan di kode tapi di environment.
Kalau PHP aktif, lalu buat file uji sederhana dan jalankan via server local:
<?php
phpinfo();
Kalau phpinfo() tampil di browser, maka PHP berjalan benar.
Kesimpulan
Yang paling mungkin terjadi adalah:
- Anda membuka file secara langsung dari disk, bukan via server web
- atau PHP tidak aktif untuk folder tersebut
- atau output dibuffer oleh ob_start()
Jadi “script tidak berfungsi” bukan berarti kode salah — bisa jadi skrip tidak pernah dieksekusi oleh PHP.
Kalau mau, saya bisa bantu buatkan langkah-langkah paling cepat untuk mengecek:
1. apakah PHP aktif di komputer Anda,
2. apakah URL benar,
3. dan cara debug action tanpa mengganggu semua script.
ini
https://about.parmi.web.id/index.php
sudah berkali-kali
Kalau URL itu sudah dibuka berkali-kali, tapi hasil tidak berubah, kemungkinan besar bukan masalah kode itu sendiri
Yang paling sering terjadi adalah:
- Anda membuka file yang salah
- atau server tidak menjalankan PHP untuk file itu
- atau output dibuffer, jadi debug tidak kelihatan
- atau URL yang dibuka bukan file yang sedang Anda edit
Langkah paling cepat untuk cek
1. Buka source halaman di browser
Cari tombol: - View Source / Lihat Sumber Halaman
Kalau Anda melihat baris seperti:
<?php
global $action;
...
maka artinya browser benar-benar menampilkan kode PHP mentah, bukan hasil eksekusi PHP.
Kalau begitu, server tidak menjalankan PHP untuk halaman itu.
2. Cek apakah URL yang dibuka memang file PHP yang benar
Kalau yang Anda edit adalah index.php, lalu URL yang dibuka harusnya bukan hanya root index.php, tapi biasanya:
https://about.parmi.web.id/admin/index.php
Bukan:
https://about.parmi.web.id/index.php
Karena file yang Anda tunjuk berada di folder admin.
3. Coba debug paling ekstrim di awal file
Masukkan ini di paling atas index.php, sebelum semua include:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
global $action;
var_dump($action);
exit;
Kalau setelah itu browser masih kosong atau menampilkan kode PHP mentah, artinya PHP tidak diproses.
4. Cek apakah ada ob_start() yang menahan output
Di file ini memang ada:
ob_start();
Ini bisa menahan output sampai script selesai, tapi kalau script berhenti dengan exit; biasanya output tetap dibuang kalau ada buffer yang belum di-flush. Jadi untuk debug, lebih aman pakai:
ob_end_clean();
var_dump($action);
exit;
Atau:
echo "DEBUG ACTION = ";
var_dump($action);
exit;
Yang paling mungkin di kasus Anda
Karena Anda bilang “sudah berkali-kali” dan tidak ada perubahan, kemungkinan besar:
- URL yang dibuka bukan file yang Anda edit
- atau file yang dibuka bukan file PHP yang diproses
- atau PHP server environment memang tidak aktif untuk project ini
Rekomendasi paling praktis
Buka URL:
https://about.parmi.web.id/admin/index.php?action=editLalu lihat source halaman
Jika source menampilkan
<?php, berarti PHP tidak dijalankanJika source menampilkan HTML, berarti PHP dijalankan tapi kemungkinan
global $actionmasih belum diisi
Kalau mau, saya bisa bantu bikin debug yang paling aman untuk index.php, misalnya:
- debug nilai $action
- debug apakah file tersebut benar-benar dipanggil
- debug apakah switch($action) sama sekali tidak masuk karena $action NULL atau tidak ada.
cara 3 tak ada efek sama sekali
Itu tanda paling jelas: file tidak dieksekusi sebagai PHP
Kalau Anda menambahkan:
error_reporting(E_ALL);
ini_set('display_errors', 1);
global $action;
var_dump($action);
exit;
dan hasilnya masih sama sekali tidak berubah, berarti kemungkinan besar:
- file tidak dijalankan oleh PHP
- URL yang dibuka tidak mengarah ke file yang sedang Anda edit
- browser sedang menampilkan file statis / halaman cache
- output dibungkus oleh buffering dan tertutup sebelum tampil
Yang paling mungkin terjadi
Karena Anda membuka:
https://about.parmi.web.id/index.php
dan file yang sedang Anda edit adalah:
/admin/index.php
maka bisa jadi Anda tidak sedang mengakses file yang benar.
Untuk script admin, URL yang benar biasanya:
https://about.parmi.web.id/admin/index.php
bukan:
https://about.parmi.web.id/index.php
Coba langkah ini langsung
Buka URL ini di browser:
https://about.parmi.web.id/admin/index.php?action=edit
Kalau browser masih menampilkan halaman biasa, maka: - bisa jadi request diarahkan ke file lain - atau server tidak menjalankan PHP untuk folder admin - atau ada rewrite/redirect yang mengubah path
Cek output mentah
Buka browser developer tools / view source, lalu lihat apakah ada teks seperti:
<?php
var_dump($action);
exit;
Kalau ada, berarti browser menampilkan source PHP mentah. Itu artinya server tidak menjalankan PHP.
Kemungkinan yang paling tinggi
Yang paling mungkin adalah:
- Anda membuka URL yang salah
- atau file tenaga server tidak menjalankan PHP untuk folder ini
- atau karena ob_start() meng-buffer output, dan Anda tidak melihat hasil debug sampai script selesai
Kalau ingin memastikan, coba tambahkan exit; langsung di awal file sebagai tes paling ekstrem, lalu buka URL yang sebenarnya. Jika halaman masih tetap normal, maka file yang dibuka bukan yang Anda edit.
Jawaban singkat
Kalau echo, var_dump, dan exit sama sekali tidak ada efek, maka yang terjadi adalah:
skrip tidak dieksekusi oleh PHP pada URL yang Anda buka
Itu bukan soal sintaks global $action atau switch($action). Itu soal environment / URL / server / path.
Kalau mau, saya bisa bantu buatkan: - cara cek URL yang benar - cara membuktikan PHP aktif atau tidak - atau cara menempatkan debug yang paling aman di index.php supaya hasil terlihat.
https://about.parmi.web.id/admin/index.php?action=edit
ada hasil :
NULL
Ini artinya
Kalau URL ini:
https://about.parmi.web.id/admin/index.php?action=edit
dan hasil debug menunjukkan:
NULL
maka artinya:
- variabel
$actionmemang ada di request, tetapi belum diisi ke variabel global - atau hasilnya tidak dibaca dari
$_GET['action'] - atau file ini memang tidak mengisi
$actiondari query string
Kenapa bisa NULL?
Karena di file Anda, yang ada hanya:
global $action;
dan itu TIDAK otomatis membaca dari URL.
global $action; hanya berarti:
“gunakan variabel global bernama
$actionyang sudah ada”
Bukan:
“baca dari
$_GET['action']”
Solusi yang benar
Anda perlu set $action dari request dulu, misalnya:
<?php
global $action;
if (isset($_GET['action'])) {
$action = $_GET['action'];
} else {
$action = 'list';
}
Atau yang lebih singkat:
<?php
global $action;
$action = $_GET['action'] ?? 'list';
Lalu:
switch ($action) {
case 'edit':
echo "edit";
break;
default:
echo "list";
break;
}
Untuk file Anda
Tambahkan ini di awal sebelum switch($action):
global $action;
$action = $_GET['action'] ?? 'list';
Jadi file itu akan menjadi seperti:
<?php
global $action;
$action = $_GET['action'] ?? 'list';
var_dump($action);
exit;
Kalau URL Anda:
https://about.parmi.web.id/admin/index.php?action=edit
maka hasilnya akan menjadi:
string(4) "edit"
dan bukan NULL.
Kesimpulan
Sekarang kita sudah tahu:
- global $action; saja tidak memberi nilai
- hasil NULL berarti variabel tidak diisi
- URL ?action=edit baru benar-benar terlihat kalau Anda pakai:
$action = $_GET['action'] ?? 'list';
Kalau Anda mau, saya bisa bantu tuliskan blok yang tepat untuk index.php agar $action otomatis terbaca dari URL dan langsung masuk ke switch($action).
Bagaimana menampilkan atau hanya mencari/menampilkan index.php di seluruh folder dengan vs code ini ?
Saya akan kasih cara paling cepat untuk mencari file index.php di workspace VS Code, dan cara membukanya dari hasil pencarian.
Cara cepat mencari semua file index.php di workspace VS Code
1. Gunakan pencarian file
- Tekan:
Ctrl+Shift+Funtuk pencarian teks, atauCtrl+Puntuk pencarian file
Kalau yang Anda mau adalah file bernama index.php, cara paling cepat adalah:
- tekan Ctrl+P
- ketik: index.php
- pilih file yang muncul
Ini akan mencari file berdasarkan nama di workspace.
2. Gunakan Explorer / Search file
Di sidebar kiri: - klik file explorer - lalu fokus ke workspace - ketik nama file di search box bila tersedia
Kalau workspace besar, lebih mudah:
- gunakan Ctrl+P
- lalu ketik index.php
3. Jika ingin mencari semua file index.php dalam folder tertentu
Gunakan pencarian file dengan path:
- Ctrl+P
- ketik: index.php
- atau **/index.php
Kalau ingin semua hasil, bisa juga:
- buka Search View: Ctrl+Shift+F
- ketik: index.php
- tapi ini mencari teks, bukan nama file
Untuk mencari nama file, yang paling andal adalah Ctrl+P.
4. Jika file terlalu banyak
Pakai pencarian penuh path:
- Ctrl+P
- lalu ketik:
- index.php
- index.php
- **/index.php
5. Menampilkan semua index.php di hasil pencarian
VS Code tidak punya cara “tampilkan semua file index.php” di Search View seperti file explorer, tetapi Ctrl+P adalah cara paling tepat untuk membuka file berdasarkan nama.
Untuk project Anda
Di workspace ini, file yang relevan adalah: - index.php - index.php
Jadi Anda bisa:
- tekan Ctrl+P
- ketik index.php
- pilih file itu
atau:
- tekan Ctrl+P
- ketik index.php
- pilih index.php
Kalau ingin mencari isi file tertentu
Kalau Anda ingin cari semua file yang berisi switch($action) atau global $action, pakai:
- Ctrl+Shift+F
- ketik: switch($action)|global \\$action
Kalau mau, saya juga bisa bantu cara: - mencari file tertentu di folder admin saja - mencari file yang nama/isinya mengandung index.php - atau membuat filter pencarian di VS Code yang paling cocok untuk project ini.
ternyata memang ada 2 index.php
satu di root
satu lagi di /admin
dan ternyata benar global = $action di sini, bukan di index.php root
clear masalahnya
Benar, itu sudah memperjelas akar masalah
Kalau ada dua file: - index.php di root - index.php di folder admin
maka yang sedang Anda debug dan yang punya switch($action) adalah index.php, bukan index.php.
Jadi:
- index.php bisa saja hanya halaman utama situs
- index.php adalah file admin yang memproses aksi seperti
edit,delete,list, dll. global $action;di index.php memang bukan dari root file, melainkan dari admin script yang dipanggil untuk operasi backend
Artinya:
Masalahnya sudah jelas:
$actiontidak ada di index.php$actionhanya ada di index.php- dan itu tidak otomatis dibuat oleh root file
- harus diisi dari request, atau dari file lain yang memanggil admin script
Karena itu, sekarang logikanya menjadi:
Jika Anda buka:
https://about.parmi.web.id/index.php
maka Anda sedang mengakses root file, bukan admin file.
Jika Anda buka:
https://about.parmi.web.id/admin/index.php?action=edit
maka Anda sedang mengakses admin script yang punya switch($action).
Kesimpulan
Salah satu akar masalah Anda adalah:
- Anda menganggap yang sedang debug adalah index.php, padahal yang benar-benar aktif untuk switch($action) adalah index.php
Jadi cara debug yang benar adalah:
- buka URL admin, bukan root
- lalu cek $_GET['action'] atau $action di admin file
- lalu lihat switch($action)
Contoh yang benar
Coba buka:
https://about.parmi.web.id/admin/index.php?action=edit
Lalu tambahkan debug di index.php:
global $action;
$action = $_GET['action'] ?? 'list';
var_dump($action);
exit;
Maka hasilnya akan menjadi:
string(4) "edit"
Jadi intinya
Masalah sudah clear:
- global $action; di file yang benar adalah index.php
- root index.php bukan tempat itu
- server/site harus dibuka via admin URL untuk melihat efeknya
Kalau mau, saya bisa bantu lanjutkan dengan cara paling tepat:
- menambahkan debug di index.php tanpa merusak aplikasi
- atau membuat contoh URL yang benar untuk memicu case "edit" dan case "list".
tambahkan debug di index.php ( di root ? ) tanpa merusak aplikasi
Saya akan kasih cara aman menambah debug di file root tanpa merusak aplikasi, supaya Anda bisa melihat apakah root file benar-benar dipanggil dan apakah ini bukan file yang sedang aktif.
Cara aman untuk debug di index.php
Jangan langsung menaruh debug tanpa syarat. Lebih aman pakai flag debug lewat URL, supaya saat tidak aktif, aplikasi tetap berjalan normal.
Tambahkan ini di paling atas index.php:
<?php
if (isset($_GET['debug'])) {
error_reporting(E_ALL);
ini_set('display_errors', 1);
echo "<pre>";
var_dump($_GET);
var_dump($GLOBALS['action'] ?? null);
echo "</pre>";
exit;
}
?>
Lalu buka:
https://about.parmi.web.id/index.php?debug=1
Kalau yang benar-benar ingin dicek adalah admin/index.php, buka:
https://about.parmi.web.id/admin/index.php?action=edit&debug=1
Untuk admin file yang serius
Di admin/index.php, tempat debug yang paling aman adalah sebelum switch:
<?php
$action = $_GET['action'] ?? 'list';
if (isset($_GET['debug'])) {
echo "<pre>";
var_dump($action);
echo "</pre>";
exit;
}
?>
Dengan cara ini: - saat debug aktif, tampil nilai action - saat debug tidak aktif, aplikasi tetap berjalan normal
Catatan penting
- index.php dan index.php adalah file berbeda
- jika Anda debugging action, fokusnya di index.php, bukan root index.php
- setelah selesai, hapus blok debug atau cukup hilangkan parameter ?debug=1
Kalau mau, saya bisa bantu bikin versi debug yang langsung pas untuk index.php tanpa mengganggu app.
bantu bikin versi debug yang langsung pas untuk index.php tanpa mengganggu app.
Saya akan buatkan versi debug yang aman untuk file root, yaitu hanya aktif saat parameter debug ada di URL, dan otomatis non-aktif saat tidak dipakai.
Versi debug aman untuk index.php
Masukkan ini di paling atas file index.php, sebelum semua include dan proses utama:
<?php
if (isset($_GET['debug'])) {
error_reporting(E_ALL);
ini_set('display_errors', 1);
echo "<pre>";
echo "DEBUG MODE\n";
echo "REQUEST_URI: " . ($_SERVER['REQUEST_URI'] ?? 'n/a') . "\n";
echo "ACTION: " . ($_GET['action'] ?? 'not set') . "\n";
var_dump($_GET);
var_dump($_POST);
echo "</pre>";
exit; // berhenti di sini supaya app tidak lanjut
}
Lalu buka URL seperti ini:
https://about.parmi.web.id/index.php?debug=1
atau untuk admin:
https://about.parmi.web.id/admin/index.php?action=edit&debug=1
Bila ingin melihat variabel $action saja
Gunakan ini di index.php, tepat sebelum switch($action):
if (isset($_GET['debug'])) {
echo "<pre>";
var_dump($action ?? null);
echo "</pre>";
exit;
}
Kalau $action belum di-set, hasilnya akan NULL.
Catatan penting
- Ini aman karena hanya aktif saat ada parameter
?debug=1 - Setelah debugging selesai, cukup hapus blok debug atau buka URL tanpa
?debug=1 - Ini tidak merusak aplikasi karena tidak memodifikasi flow normal saat mode debug off
Kalau mau, saya bisa bikin versi yang langsung pas untuk index.php dengan debug lengkap untuk action, item, dir, dan GLOBALS.
bikin versi yang langsung pas untuk index.php dengan debug lengkap untuk `action`, `item`, `dir`, dan `GLOBALS`
Saya akan menaruh blok debug yang hanya aktif saat parameter debug ada di URL, lalu mencetak action, item, dir, dan GLOBALS lengkap tanpa mengganggu jalur normal saat tidak dipakai.
Berikut versi debug yang aman untuk index.php. Blok ini hanya aktif jika URL punya parameter ?debug=1, jadi app normal ketika debug tidak dipakai.
Tambahkan ini di paling atas file index.php, segera setelah <?php:
if (isset($_GET['debug'])) {
error_reporting(E_ALL);
ini_set('display_errors', 1);
echo "<pre>";
echo "=== DEBUG START ===\n";
echo "REQUEST_URI: " . ($_SERVER['REQUEST_URI'] ?? 'n/a') . "\n";
echo "action: " . (isset($_GET['action']) ? $_GET['action'] : 'NOT SET') . "\n";
echo "item: " . (isset($_GET['item']) ? $_GET['item'] : 'NOT SET') . "\n";
if (isset($action)) {
var_dump($action);
} else {
echo '$action is NOT SET' . "\n";
}
if (isset($item)) {
var_dump($item);
} else {
echo '$item is NOT SET' . "\n";
}
if (isset($dir)) {
var_dump($dir);
} else {
echo '$dir is NOT SET' . "\n";
}
echo "--- $_GET ---\n";
var_dump($_GET);
echo "--- $_POST ---\n";
var_dump($_POST);
echo "--- $GLOBALS ---\n";
var_dump($GLOBALS);
echo "=== DEBUG END ===\n";
echo "</pre>";
exit;
}
Lalu buka:
https://about.parmi.web.id/index.php?debug=1
atau, kalau ingin cek parameter action dari URL:
https://about.parmi.web.id/index.php?action=edit&item=test.txt&debug=1
Versi yang lebih fokus ke admin
Kalau Anda ingin debug yang benar-benar ditujukan ke admin, lakukan juga ini di index.php sebelum switch($action):
if (isset($_GET['debug'])) {
error_reporting(E_ALL);
ini_set('display_errors', 1);
echo "<pre>";
echo "=== ADMIN DEBUG ===\n";
echo "action: " . (isset($_GET['action']) ? $_GET['action'] : 'NOT SET') . "\n";
echo "item: " . (isset($_GET['item']) ? $_GET['item'] : 'NOT SET') . "\n";
var_dump($action ?? null);
var_dump($item ?? null);
var_dump($dir ?? null);
var_dump($GLOBALS);
echo "</pre>";
exit;
}
Lalu buka:
https://about.parmi.web.id/admin/index.php?action=edit&item=test.txt&debug=1
Catatan
- Ini aman dan tidak merusak app
- Saat
?debug=1tidak ada, file berjalan seperti biasa - Saat selesai debugging, cukup hapus blok atau jangan gunakan parameter
debug
Kalau Anda mau, saya bisa bantu sesuaikan blok debug ini untuk case tertentu seperti edit, delete, atau list, agar tidak perlu menampilkan semuanya sekaligus.