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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:33:07+00:00 2026-06-01T16:33:07+00:00

We have REST API that we want only our domain has access to and

  • 0

We have REST API that we want only our domain has access to and that spoofed requests are not sent. To do so, the only thing coming in my mind was checking the referrer $_SERVER['HTTP_REFERER']. However the docs say that:

The address of the page (if any) which referred the user agent to the
current page. This is set by the user agent. Not all user agents will
set this, and some provide the ability to modify HTTP_REFERER as a
feature. In short, it cannot really be trusted.

So let’s say our main API requests/gate file is:

www.example.com/api/gate.php

How do I make it secure so that only requests from own domain are served and all other disregarded? I have read a little about http authentication and setting up private keys or secret but I am looking for a simple way so only our own domain can send requests to that 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-06-01T16:33:08+00:00Added an answer on June 1, 2026 at 4:33 pm

    As already stated, HTTP_REFERRER and REMOTE_ADDR could be potentially spoofed, and thus can’t be trusted to implement said functionality. Also keep in mind that in a shared hosting context other accounts in the same server also have the same IP.

    A quick solution could be to use Basic Authentication to authenticate the requests to the API. This won’t filter by IP or referrer URL/IP but will ensure that requests come from a trusted source.

    In a Apache environment setting up Basic Authentication is as easy as creating the .htaccess and .htpasswd files, and putting them in the root directory of your API.

    You can create both files using the following generators:
    .htaccess generator
    .htpasswd generator

    After setting up Basic Authentication, authenticating your requests in PHP is as easy as accessing your API in the following fashion:

    username:password@example.com

    So no extra code needs to be developed to set any headers to authenticate your requests. Anyone accessing the URL will be prompted for credentials, denying access if authentication fails.

    enter image description here

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

Sidebar

Related Questions

I have a portion of my site that has a lightweight xml/json REST API.
We have a website that we want to provide web based API access to
I currently have a REST API that must be authenticated via BasicAuth, but later
I'm developing a REST api. To simplify my question, I have an API that
Say I have a REST API in java, and it supports responses that are
We are currently designing a REST API that we want to publish in a
I have a backend system which i access via a REST based API and
I have a REST api that will accept a version via a custom HTTP
Twitter have a 150 requests per hour limit for their unauthenticated REST API, I
I have a scenario in which I have REST API which manages a Resource

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.