1

I have a php script which updates a database. I want to be sure that no one else can call my script remotely and execute it.

I tried this code but it did not work, the refer was always empty because I use https connection.

if (strpos($_SERVER['HTTPS_REFERER'], 'linkedfilm.com') == false) 
{
    exit();
}

The server is Apache server.

Thanks.

2
  • Maybe design a RBAC. User must be logged in and of a certain role (admin for example). Commented Jan 20, 2019 at 13:53
  • Are you looking for this : stackoverflow.com/questions/51129624/… ? Commented Jan 20, 2019 at 14:15

2 Answers 2

3

Hello Daina Hodges,

You got a few options to secure this .php script.

  1. You can secure this script by moving it into another directory outside of your DOCUMENT_ROOT
  2. You can add the .htaccess
  3. You can allow only local ip
Sign up to request clarification or add additional context in comments.

1 Comment

or you can allow only command-line access
1

You could use .htaccess and put your script in a password protected directory.

Or you could use some sort of login and authentication routines on your site so you can login and access that script.

Or you could pass a 'secret' key with you call to the script, quick and dirty

if( $_GET['secret'] != "mysecret" ) exit();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.