如何处理多个包含在不同的php文件中?

时间:2015-07-30 09:52:46

标签: php

我想通过php文件在WhatsApp上发送消息。我已经发现了这样做的图书馆,它以这种方式运作:

<?php
include_once './src/whatsprot.class.php';

function send($target,$message){
$username = "phone";
$password = "password";
$w = new WhatsProt($username,"Nickname", true); //Name your application by replacing “WhatsApp Messaging”
$w->connect();
$w->loginWithPassword($password);

$w->SendPresenceSubscription($target); //Let us first send presence to user
$w->sendMessage($target,$message ); // Send Message
}

send("phone","Text of the message");

&GT;

如果我尝试执行此操作或通过php Web服务器启动它,它可以工作。如果我尝试从另一个php文件调用方法send($target,$message);,就像这样,它不起作用:

 <?php 

include "whatsapp.php";

send($target, $message);

?>

问题是什么?我该如何解决?

1 个答案:

答案 0 :(得分:1)

  

如果我尝试从另一个php文件调用方法send($target,$message);,它就不起作用了   问题是什么?

很可能另一个php文件位于不同的目录中,这个命令不起作用:

include_once './src/whatsprot.class.php';

尝试使用绝对路径来存档。