Dean219 Dean219 - 6 months ago 12
PHP Question

Make php method available from outside root/index.php

Im having an issue exposing a function to other php files. I would like to allow another php file to access a method from essentially root/index.php, or just /index.php. However when i use include('/index.php') it instead includes the index.php file from the current directory i.e /search/index.php or /latest/index.php

Ultimately what im trying to solve is how to call a method stored in my /index.php file from root/mydirectory/index.php:

if (isset($_GET['id'])) {
runMethod($log);//function i want to call, defined in regular /index.php file
} else {


method in root/index.php

function runMethod($log) {

Is there a simple way to share this method without using a global.php file or to just expose the method from the root/index.php file?

Any help would be appreciated.


Include your file like this

include("../index.php"); // one folder up to the current folder