Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8240653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:33:42+00:00 2026-06-07T20:33:42+00:00

just wondering how it would be possible to recursively search through a website folder

  • 0

just wondering how it would be possible to recursively search through a website folder directory (the same one as the script is uploaded to) and open/read every file and search for a specific string?

for example I might have this:

search.php?string=hello%20world

this would run a process then output somethign like

"hello world found inside"

httpdocs
/index.php
/contact.php

httpdocs/private/
../prviate.php
../morestuff.php
../tastey.php

httpdocs/private/love
../../goodness.php

I dont want it to link- crawl as private files and unlinked files are round, but i’d like every other non-binary file to be access really.

many thanks

Owen

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:33:43+00:00Added an answer on June 7, 2026 at 8:33 pm

    Two immediate solutions come to mind.

    1) Using grep with the exec command (only if the server supports it):

    $query = $_GET['string'];
    $found = array();
    exec("grep -Ril '" . escapeshellarg($query) . "' " . $_SERVER['DOCUMENT_ROOT'], $found);
    

    Once finished, every file-path that contains the query will be placed in $found. You can iterate through this array and process/display it as needed.

    2) Recursively loop through the folder and open each file, search for the string, and save it if found:

    function search($file, $query, &$found) {
        if (is_file($file)) {
            $contents = file_get_contents($file);
            if (strpos($contents, $query) !== false) {
                // file contains the query string
                $found[] = $file;
            }
        } else {
            // file is a directory
            $base_dir = $file;
            $dh = opendir($base_dir);
            while (($file = readdir($dh))) {
                if (($file != '.') && ($file != '..')) {
                    // call search() on the found file/directory
                    search($base_dir . '/' . $file, $query, $found);
                }
            }
            closedir($dh);
        }
    }
    
    $query = $_GET['string'];
    $found = array();
    search($_SERVER['DOCUMENT_ROOT'], $query, $found);
    

    This should (untested) recursively search into each subfolder/file for the requested string. If it’s found, it will be in the variable $found.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just wondering if it would be possible to open new browser window/tab inside
Hey, I'm just wondering if it would be possible to convert videos to mp3
I was just wondering, for an LDAP structure, would it be possible for a
I'm just wondering if it would be possible (and legal) to port an Android
I'm just starting to learn LINQ, I'm wondering if it would be possible to
I was just wondering if it would be possible to bind the list of
I saw just wondering how it would be possible to change a src every
I'm just wondering if it's possible to use one regular expression to match another,
Just wondering if this is possible. What I would actually like to do is
I am just wondering whether it would be possible to replicate only a table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.