我一直致力于一个项目,该项目涉及创建 PHP 服务,使其在本地与 Vertrigo 一起工作,然后将其上传到 IBM Bluemix。
该代码在本地似乎工作得很好,但是当尝试在 Bluemix 中找出代码时,它开始失败。
该项目由 3 个文件组成:index.html
、client.php
和 server.php
。显然,问题出在 client.php
和 server.php
之间。当我尝试从 client.php
调用 server.php
中定义的函数时,它只会跳过调用该函数的行,并继续执行其余部分。
这是 client.php 代码的一部分:
<?php
if(isset($_POST['saludo']) && !empty($_POST['nombre']) && !empty($_POST['apellido'])) {
require_once ('nusoap.php');
$soapclient = new soapclient( 'server.php');
$resultado = $soapclient->call('funcionsaludo',array( 'nombre'=>$_POST['nombre'],'apellido'=>$_POST['apellido']));
$html = <<<html
<html>
<head></head>
<title>Saludando...</title>
<body bgcolor = "#9d1fc4" text = "black"><center><img src = "/images/3.jpg"></center><br><br>
<center><b>$resultado<br><br><a href='index.html' style='color: #ffffff'>INICIO</a></b></center>
</body>
</html>
html;
echo $html;
}
被跳过的部分是对文件 server.php
的调用,即:
$soapclient = new soapclient( 'server.php');
$resultado = $soapclient->call('funcionsaludo',array( 'nombre'=>$_POST['nombre'],'apellido'=>$_POST['apellido']));
最后,我展示了 server.php 文件的一部分:
<?php
require_once('nusoap.php');
$server = new soap_server;
$server->register('funcionsaludo');
$server->register('getData');
$server->register('insertData');
function funcionsaludo ($nombre,$apellido) {
return "<html><head></head><body>Hola $nombre $apellido<br><br></body></html>";
}
结果,函数funcionsaludo
返回一个由“Hola $nombre $apellido”组成的字符串,但它似乎被跳过了,因为该字符串没有显示在屏幕上。
我还想补充一下,所有 3 个文件 index.html
、client.php
、server.php
以及使用的库nusoap.php
已全部上传到 IBM Bluemix DevOps Services 内的默认项目文件夹,并且它们不在不同的文件夹或类似文件夹中。此外,我在日志中没有看到任何可以提供一些线索的错误消息。
非常感谢您提供有关为何跳过 server.php 文件中的该函数的任何帮助。谢谢!
最佳答案
嗯,在你的 HTML 变量中你有一些标签,但是为了 PHP 将其解释为文本,你应该用双引号/单引号它,如下所示:
$html = '<html>
<head></head>
<title>Saludando...</title>
<body bgcolor = "#9d1fc4" text = "black"><center><img src = "/images/3.jpg"></center><br><br>
<center><b>$resultado<br><br><a href="index.html" style="color: #ffffff">INICIO</a></b></center>
</body>
</html>';
echo $html;
否则它将被解释为 PHP 方法和函数,而这些方法和函数并不存在。我建议您更改此设置并重试,如果不起作用,请打开浏览器上的开发人员工具并查看是否渲染了任何内容(例如页面 HTML 结构)。
关于php - 尝试使 PHP 代码在 bluemix 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37753378/