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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:50:31+00:00 2026-05-25T21:50:31+00:00

Here’s the situation. I have a primary web server that needs to be able

  • 0

Here’s the situation.

I have a primary web server that needs to be able to access files on a remote web server with PHP. I also have a remote server. The files on the remote server are private. That is, I only want to access them through my PHP script on the primary server.

How do I only allow access to a directory of files from the primary server, but deny access to anyone else?

  • 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-25T21:50:32+00:00Added an answer on May 25, 2026 at 9:50 pm

    In your .htaccess file:

    AuthName "Protected" 
    AuthType Basic 
    <Limit GET POST> 
    order deny,allow 
    deny from all 
    allow from YOUR.SERVER.IP.ADDRESS 
    </Limit> 
    

    That’s how I’d do it. Place that in the .htaccess file in the directory you are trying to protect. Only requests which come from YOUR.SERVER.IP.ADDRESS (obviously change that to your server IP) will be allowed, everyone else gets a 403 error.

    Given your comments, then you’d want to do it some way with access tokens or something. The way I’d set it up would be to make a PHP script on the remote file server which will serve the files if an access token is matched, and you could just fetch the file with cURL then. If the access token is not matched, set the 403 Forbidden header.

    Then, they’d only be able to access the files with your access token. To make the token dynamic so it can’t be stolen easily, you could take the MD5 hash of a salt plus a dynamic variable that could be shared between servers, like the day of the month. The more frequently the dynamic variable updates, the more frequently the access token updates and the more secure you’ll be. Try to keep what you’re using for a salt and the hashing algorithm secret, for the best protection.

    Basic script you could keep on the file server:

    if($_GET['access'] != md5('aihdhgsa8gas8gasgsa8asgdds' . $YOUR_UPDATING_VALUE)){
        //Improper access hash
        header('HTTP/1.1 403 Forbidden');
        die();
    }
    
    $files = array('blah.png', 'lol.exe');
    $file_to_serve = $_GET['file'];
    if(!in_array($file_to_serve, $files)){
        //File isn't in our array
        header('HTTP/1.1 403 Forbidden');
        die();
    }else{
        die(file_get_contents($file_to_serve)); //Serve however you need.
    }
    

    And on your main server:

    $file = file_get_contents('http://example.com/serve.php?file=' . $filename . '&access=' . md5('aihdhgsa8gas8gasgsa8asgdds' . $YOUR_UPDATING_VALUE));
    

    These are very rough examples and you’d need to rework the serving and fetching to your system configuration, but you get the point. $YOUR_UPDATING_VALUE should be something both servers can calculate that updates kinda frequently, I’d advise against microtime because there would be a delay in fetching from the other server and it’d always be false.

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

Sidebar

Related Questions

Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here is my code (Say we have a single button on the page that
Here is what I am trying to achieve in PHP: I have this string:
Here is my problem...I have a page that loads a list of clients and
Here is my situation: I am using telerik with winform. I have a dataset
Here is my situation: I have a controller action called OrderFromCategory which fills a
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form
Here's a coding problem for those that like this kind of thing. Let's see

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.