Xampp localhost/dashboard – Xampp

Photo of author
Written By M Ibrahim
composer-php dashboard localhost xampp

The Solutions:

Solution 1: Edit index.php in htdocs folder

To display directories in XAMPP, edit the file index.php located in the htdocs folder. Replace the existing code with the following:

<!DOCTYPE html>
<html>
<head>
    <title>Directory Listing</title>
    <style>
        table {
            border-collapse: collapse;
            width: 100%;
        }
        th, td {
            border: 1px solid black;
            padding: 5px;
            text-align: center;
        }
    </style>
</head>
<body>
    <h1>Directory Listing</h1>
    <table>
        <thead>
            <tr>
                <th>Name</th>
                <th>Size</th>
                <th>Type</th>
                <th>Last Modified</th>
            </tr>
        </thead>
        <tbody>
            <?php
            // Get the current directory
            $dir = $_SERVER['DOCUMENT_ROOT'];

            // Open the directory
            $dh = opendir($dir);

            // Loop through the directory
            while (($file = readdir($dh)) !== false) {
                // Skip hidden files and directories
                if ($file[0] == '.' || $file == 'index.php') {
                    continue;
                }

                // Get file information
                $file_info = stat($dir . '/' . $file);

                echo "<tr>";
                echo "<td><a href='$file'>$file</a></td>";
                echo "<td>" . number_format($file_info['size']) . " bytes</td>";
                echo "<td>" . filetype($dir . '/' . $file) . "</td>";
                echo "<td>" . date("Y-m-d H:i:s", $file_info['mtime']) . "</td>";
                echo "</tr>";
            }

            // Close the directory
            closedir($dh);
            ?>
        </tbody>
    </table>
</body>
</html>

This code will generate a table that lists all the files and directories in the current directory, along with their size, type, and last modified date.

Solution 2: Deleting or Modifying Index.php File

To resolve the issue and access the directories and files using “localhost,” follow these steps:

  1. Navigate to the “xampp\htdocs” directory on your computer.
  2. Locate the file named “index.php.”
  3. Do either of the following:
    • Delete the “index.php” file.
    • Rename the “index.php” file to “index.txt” (or any other name you prefer).
  4. Once the index.php file is removed or renamed, type “localhost” in your browser’s address bar and hit enter.
  5. You should now see a list of directories and files within the “htdocs” directory.

Explanation: By deleting or modifying the “index.php” file, you’re removing the default page that was previously displayed when you typed “localhost” in your browser. This allows you to see the actual contents of the “htdocs” directory, which includes the list of subdirectories and files.

Note: If you wish to use the “xampp\htdocs\index.php” file again, restore it to its original name (“index.php”) and delete the “index.txt” file (or whatever name you gave it).

Solution 3: Change the index.php file

Navigate to the following directory in your XAMPP installation:

XAMPP\htdocs\

Locate the index.php file and open it with a text editor like Notepad or Sublime Text.
Modify the file as follows:


<?php
    if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
        $uri = 'https://';
    } else {
        $uri = 'http://';
    }
    $uri .= $_SERVER['HTTP_HOST'];
    header('Location: '.$uri.'/dashboard/');
    exit;
?>

Restart the XAMPP server and access localhost in your browser. This should allow you to see the directories and files.

Solution 4: Type in your URL localhost/[name of your folder in htdocs]

XAMPP has a default landing page called "dashboard" that is located in the "htdocs" folder. When you type "localhost" in your browser, it will automatically redirect you to "localhost/dashboard".

If you want to see the directories and files in your "htdocs" folder instead, you can type in the following URL in your browser:

localhost/[name of your folder in htdocs]

For example, if you have a folder called "my_project" in your "htdocs" folder, you would type in the following URL:

localhost/my_project

This will take you to the directory listing for your "my_project" folder, where you can see all of the files and directories inside it.

Solution:

When you type “localhost” in your browser, it tries to open the file named “index.php” or “index.html” in the “htdocs” folder of XAMPP. If either of those files exists, it will open the file; otherwise, it will display the directories and files within the “htdocs” directory.

To see the directories and files in "localhost," you can rename the "index.php" or "index.html" file to something else, such as "index2.php." This will prevent the browser from opening the file and will instead display the contents of the "htdocs" directory.