简体   繁体   中英

How to include php page has my class

I have a problem while including my own php class page from its server.

I hosted my php classes page like http://my.website.com/phpclasses.php

and tried to call it from another host such as:

<?php 
include ("http://my.website.com/phpclasses.php");
?>

By the way, the php class page has a class named 'test' and activated in it by this variable, here is a quick view about it:

phpclasses.php

class test{
somefunctions();
somefunctions();
}
$test = new test();

I requested this page from another website like this:

anotherwebsite.php:

 $newclass = new test();
 $newclass->somefunctions();

Notice that i've activated the class twice, once in its page, and again in the another website, but failed and returns nothing.

How could it work?

It's a bad idea to include over HTTP unless your printing PHP Code to the browser. Otherwise it will not work.

It's best to include locally:

Class.php

 class Test{
        public function __construct(){
            return TRUE;
        }            
 }

index.php

include "Class.php";

$Class = new Test();

Both files are located on the same server (same directory).. if including in other directories, add correct path to the file:

 include "/Core/Class.php";

Being interpreted as

/ - Root Directory

Core - Sub directory

Class.php - File name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM