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 7022619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:36:21+00:00 2026-05-27T23:36:21+00:00

My script: $secret = check_input($_GET[‘secret’]); if(isset($_POST[‘register’])) { if (isset($secret) || !empty($secret)) { if (file_exists(ROOT

  • 0

My script:

$secret = check_input($_GET['secret']);
if(isset($_POST['register'])) {
    if (isset($secret) || !empty($secret)) {
        if (file_exists(ROOT . '/intl/codes/' . $secret)) {
            unlink(ROOT . '/intl/codes/' . $secret);
            $trusted = 'yes';
        } else {
            $trusted = 'no';
        }
    }
//$_POST['register'] register details...
}
  1. Is there another way to do it (simplier, etc.)?
  2. If $secret doesn’t exist in the /codes/ folder, it produces Warning: unlink Is a directory How to get rid of that?
  3. Why $trusted always gives yes even if the file doesn’t exist ?
  • 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-05-27T23:36:22+00:00Added an answer on May 27, 2026 at 11:36 pm

    To delete a directory, you should be using rmdir() instead of unlink().

    $secret = check_input($_GET['secret']);
    if(isset($_POST['register'])) {
        if (!empty($secret)) {
            if(file_exists(ROOT . '/intl/codes/' . $secret)) {
                rmdir(ROOT . '/intl/codes/' . $secret);
                $trusted = 'yes';
            } else {
                $trusted = 'no';
            }
        }
        //$_POST['register'] register details...
    }
    

    Although, there is a serious security risk here! If your check_input() does not properly sanitize $secret, you could rmdir('/intl/codes/../') which is the same as deleting /intl/.
    Try something like this:

    $allowed = ROOT. '/intl/codes/';
    $path = realpath($allowed . check_input($_GET['secret']));
    
    if(strpos($path, $allowed) === 0) {  //Check that $path is within allowed directory
        if(is_dir($path)) {
            rmdir($path);
        } else if(file_exists($path)) {
            unlink($path);
        } else {
            echo "File/folder not found";
        }
    } else {
        echo "Untrusted user tried to delete outside of allowed directory";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I run this script: define('SECRET', vJs;ly-W\XDkD_2'-M7S2/ZRRBobxt5); echo sha1(SECRET . 'zcbkeyky' . 'aaa@bbb.com') . \n;
Script: http://keith-wood.name/countdown.htm Daily json response: items: { fajr: '5:23 am', sharooq: '7:23 am', dhur:
My script is generating a very long URL just like the one below and
The script below will replace selected word in a textarea. But it only works
My script is acting strange. After a foreach loop, the script stops. I don't
The script to setup up the SQL Server database for Elmah has a warning
The script runs fine when stdout/stderr are not redirected. When I add both stderr
My script puts together a set of htaccess rules based on information passed into
The script below, test.php, is intended to be placed in a specific directory of
The script below resides in my theme's functions.php file. It is designed to show

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.