0

I have a PHP class on a subdomain I want to use in another subdomain. I can include it on the second subdomain but when I call the class, I have a "class not found" error.

On subdomain A (http://a.mydomain.com), file: MyClass.php:

class MyClass {
  public function getTest() {
    return 'Hello World !';
  }
}

On subdomain B (http://d.mydomain.com):

include 'http://a.mydomain.com/MyClass.php';

$class = new MyClass();
echo $class->getTest();

Error displayed: Fatal error: Class 'myClass' not found in /var/www/subdomainb/index.php on line 3

Anyone has an idee to do that ?

darghan
  • 3
  • 1
  • 6
    You don't want to include using a web URL. You want to use an absolute path – Pekka Feb 07 '13 at 11:35
  • 1
    Are both subdomains on same server? If yes, you can specify a relative/absolute path. – web-nomad Feb 07 '13 at 11:40
  • It's probably a stupid idea, but you can also try and download the file to your subdomain B and then include it using relative path. – Pateman Feb 07 '13 at 11:47

2 Answers2

2

You must include files using their paths not URLs. I am not sure about your file structure but it is about like this:

include '/var/www/subdomaina/MyClass.php';

Also consider using namespaces.

seferov
  • 4,111
  • 3
  • 37
  • 75
0

See these questions:

There are quite many answers to your question on StackOverflow.

It boils down to: Never include files from remote servers.

Community
  • 1
  • 1
Sverri M. Olsen
  • 13,055
  • 3
  • 36
  • 52