PHP执行主机


PHP Exec 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,因为表没有更新,错误在哪里?

我想与其这样写:

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代替