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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:13:47+00:00 2026-05-19T02:13:47+00:00

I have a service.php class that I use to service AJAX calls from my

  • 0

I have a service.php class that I use to service AJAX calls from my website. To prevent other people accessing the service using PHP CURL I would normally check the request has come from mysite, and if they are not then just redirect to my home page e.g.

if($_SERVER['HTTP_REFERER'] != "http://www.mysite.com"){
   header('location: http://www.mysite.com');
   exit;
}

I read in the PHP holy bible:

http://www.php.net/manual/en/reserved.variables.server.php

that

“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 if this method is not reliable, my question is how can I reliably check that requests to my service file have come from my website?

Thanks for any help you can provide!

  • 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-19T02:13:48+00:00Added an answer on May 19, 2026 at 2:13 am

    You need to create a small session cookie, which includes time of page request, IP of the requester and some secret string which changes from time to time (i.e. is valid for an hour or so). The cookie must be encrypted. Now when the AJAX call is made, you check the cookie, compare the IP, check the secret string and act accordingly.

    But to say the truth, this will make hacker’s task more complicated, but not impossible. So you’d need to add HTTPS to the equation, and even then a good troyan on client’s computer would make false request possible. But for most scenarios the above + HTTPS would drive the attacker away.

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

Sidebar

Related Questions

I have a php web service that takes the request from android/iphone app and
I have a PHP script that grabs data from an external service and saves
I have a PHP Web application that consumes a Web Service using PHP's native
Lets say that i have 2 pages: index.php and service.php index.php sends an http-post
I have created a RESTful PHP web service using Lithium which contains comments, each
I am trying to include the Zend_Service_Amazon_S3 file by using require_once 'Zend/Service/Amazon/S3.php'; I have
I am using Google GeoCoding services. I have a PHP application which calls the
I'm using PHP 5.2 to make a website I like to have explicit names
I have a cocoa class set up that I want to use to connect
I have a web service written in PHP, that returns JSON results. It works

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.