开发者

php function call from external PHP

开发者 https://www.devze.com 2023-02-28 23:22 出处:网络
I want to call function in PHP i use require_once for this .... now i want to call the function in a particular event how it is done ?

I want to call function in PHP i use require_once for this .... now i want to call the function in a particular event how it is done ?

For example I have an function

function validateHostName($hostName) {
    if ((strpbrk($hostName, '`~!@#$^&*()=+.[ ]{}\\|;:\'",<>/?') == FALSE) && !ctype_digit($hostName) && eregi("^([a-z0-9-]+)$", $hostName) && ereg("^[^-]", $hostName) && ereg("[^-]$", $hostName)) {
        return true;
    }
    else return false;
}

in error-status.php file .. (external file) now i want to cal this file in 2.php in between here

else if ($apply == "Add") {
    //$length=$doc->getElementsByTagName('Server')->length;
    if ($addntp == "") {
        seterror("0:|: :|: Add NTP server");

        //$error_text="NTP server already ad开发者_开发问答ded"."\n"."Exiting ..."; 
        //AddLog("timeconfig.php",$error_text,ERR_INFO);
        header("Location: datetime.php");
        exit;
    } 

can u help me fast ... how it is call ... i use require function for include ....


use this .. for a function call

include 'error-status.php';
 validateHostName('myhostname'); 


I believe you can do that with changing some settings on your server. I never thought of including a php file which is on another domain.

You could use open_dir = on, and include the file with using exact path of it.

Let's say this is the domain where you have external.php to include; www.anotherdomain.com

Let's say this is the domain where you want to include external.php from www.anotherdomain.com to www.yourdomain.com

You have to have open_dir feature on, on www.anotherdomain.com. Later you can include any file from www.anotherdomain.com to any of your domains.

The point here is to have both domains hosted on the same server.

Once again, never tried or had the need to include an external php file if I didn't code it (I included files which is on another domain with using open_dir). If it is possible this would be dangerous anyway.

0

精彩评论

暂无评论...
验证码 换一张
取 消