Code sur écran d'ordinateur

PHP – How to find the origin of the call on a PHP function

It can happen that a function is only callable from one interface (console, apache…). There is a function that returns exactly what we are looking for.

In the following example, we are looking to know whether the call is from the console.

if (php_sapi_name()!"cli")
   header ("Location: http://www.sadtrombone.com/");
   die(;
}

Leave a comment