Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a php script is being called by another script on the server?

Tags:

php

I have a script scripty.php

Sometimes this script gets called through the browser.

Other times it gets called by another script on the server.

How can I (securely) check within scripty.php to see whether or not it is being called by the server?

like image 974
Bob Avatar asked Sep 05 '11 19:09

Bob


3 Answers

in the form of an http URL

The $_SERVER["REMOTE_ADDR"] variable that gives you the IP address of the client who made the request should be 127.0.0.1 when the script is called from the server.

like image 191
Pekka Avatar answered Nov 02 '22 23:11

Pekka


you can create a variable before including your script

$by_script = true;
include("new_script.php");

and check it inside

like image 6
genesis Avatar answered Nov 03 '22 00:11

genesis


Just a guess: You want to know, if the script its called trough a browser, or from CLI

var_dump(PHP_SAPI);
like image 2
KingCrunch Avatar answered Nov 03 '22 01:11

KingCrunch