我有这个脚本在我的服务器hostgator上执行一个文件。我启动了这个脚本(script.php)
<?php
echo exec('whoami');
if(function_exists('exec')) {
echo "exec is enabled";
}
$output = array();
$retval = null;
echo "<br>SONO IN HOME 000000000000000<br>";
echo exec('HOME=/home1/my username on hostgator/public_html/path to script/provaricevimento.php' , $output, $retval);
if ($retval == 0) {
echo "<br>Valore " . $output ."<br>";
echo "<br>Valore 0 " . $output[0] ."<br>";
echo "<br>Valore 1 " . $output[1] ."<br>";
echo "<br>Valore 2 " . $output[2] ."<br>";
echo "<br>Valore 3 " . $output[3] ."<br>";
echo "<br>Valore 4 " . $output[4] ."<br>";
echo "<br>Valore 5 " . $output[5] ."<br>";
}
else{
echo "Error issuing exec command! valore ritorno:".$retval."<br>";
}
echo "<br>-----------retval :$retval ------------------<br>";
print_r ($output);
echo "<br>-----------------------------<br>";
?>
和provaricevimento.php是
<?php
include '../connessione/conn.php';
$data=date('l jS \of F Y h:i:s A');
//$ric=$_GET['ricevimento'];
//$testo=$_GET['testo'];
//$url=$_GET['url'];
//$data= date("m.d.y");
$sql="INSERT INTO prova SET
testo='$testo',
url='$ric',
data='$data'";
if (@mysql_query($sql)){
echo "INSERIMENTO CON SUCCESSO: con conta : $conta e i :$i<br>";
} else
{
echo "inserimento NON avvenuto".mysql_error()."<br>";
}
?>
一切正常,返回代码为0,但我看到文件script.php没有执行provaricevimento.php,因为表没有更新,哪里出错了?
答案 0 :(得分:2)
我认为不是这一行:
echo exec('HOME=/home1/my username on hostgator/public_html/path to script/provaricevimento.php' , $output, $retval);
您可能应该使用PHP调用脚本,而不是更改Home变量:
echo exec('php5 /home1/my username on hostgator/public_html/path to script/provaricevimento.php' , $output, $retval);
但是,我不明白为什么你不能只使用PHP include
。