[Solved] keep a separate file with php class and pass variable to it [closed]


Put the class in one file, then include it using any of these options:

Includes:

include ($_SERVER['DOCUMENT_ROOT'].'/includes/class.php');

Require:

require ($_SERVER['DOCUMENT_ROOT'].'/includes/class.php');

Require Once:

require_once ($_SERVER['DOCUMENT_ROOT'].'/includes/class.php');

Or you can target the class with ajax or a form:

/includes/class.php?var=input

In the class include you would use:

if(!empty($_GET['var'])){
   //Do some check here for validation
   //let's say I'm expecting a number
   if(is_numeric($_GET['var'])){
     $var = $_GET['var'];
   }
}

Then use the var in your class.

0

solved keep a separate file with php class and pass variable to it [closed]