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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:59:09+00:00 2026-05-15T21:59:09+00:00

im new to php. I have a basic unlink php file which deletes a

  • 0

im new to php. I have a basic unlink php file which deletes a test.html. Using Apache httpserver

<?php
$fh = fopen('test.html', 'a');
fwrite($fh, '<h1>Hello world!</h1>');
fclose($fh);

unlink('test.html');
?>

So now how do i set a authentication method so that only a person with the correct username/password can access this file?

  • 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-15T21:59:10+00:00Added an answer on May 15, 2026 at 9:59 pm

    If you want the protection in PHP, you’ll need to place the unlink code inside a conditional block:

    if(ok_to_delete())
    {
        # unlink code
    }
    

    That function might look like this:

    function ok_to_delete()
    {
        # hash of your password
        if('d0be2dc421be4fcd0172e5afceea3970e2f3d940' == sha1($_POST['delete_password']))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    

    And the form:

    <form action="delete.php" method="post">
        <input type="password" name="delete_password" />
        <input type="submit" value="Delete Something" />
    </form>
    

    Putting unlink() in a conditional block prevents it from being arbitrarily executed by some other means (run from command-line, included in another file, etc.).

    There are myriad ways to write the ok_to_delete() function, of course. If you’re curious you might poke around on Google, or check out an open source project.

    For a full-blown user auth system, there are a lot of concerns regarding security (using https, whether the form can be exploited, whether you can delete arbitrary files, whether passwords are secure, etc.).

    For something simple like deleting some cache files, the example code may suffice.

    Refs:

    • $_POST
    • sha1()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 497k
  • Answers 497k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Why not convert to bytes and walk forward--obeying UTF8 character… May 16, 2026 at 11:53 am
  • Editorial Team
    Editorial Team added an answer You should put the [string release]; lines inside the for(NSString… May 16, 2026 at 11:53 am
  • Editorial Team
    Editorial Team added an answer Considering your database layout, I think it might be better… May 16, 2026 at 11:53 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm relatively new to PHP and have been writing a project using what I
I'm quite new to php and have been reading Larry Ullman book to develop
I have a basic form consisting of input fields as well as a file
I'm new to php and sql. I have a table with three columns. One
I am new to php and am asking for some coding help. I have
I have some basic pageview incrementing code set up on a LAMP server (see
I have made a little framework for php. In this project I have the
I am new to php. Trying to send confirmation about user upload. I am
In the new PHP SDK is there any way to post to a friends
New to PHP, would love to get to know it better. Currently working on

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.