浏览器无法打开php页面?

时间:2011-09-29 16:24:51

标签: php linux shell networking

首先,我展示了PHP代码....

<?php 

 echo ("hello");

 echo exec("sendip -v -p ipv6 -6s 2001::100 -p tcp -ts 21 -td 21 2001::200 2> 
 &1");

 echo ("hi");

 ?>

当我通过linux命令行输入命令时,它工作正常。命令是从2001 :: 100在2001 :: 200机器上发送一个tcp ipv6数据包。

[root@udit-pc]# sendip -v  -p ipv6 -6s 2001::100 -p tcp -ts 21 
-td 21 2001::200 > /dev/null &

/* (-v for verbose) */    

输出上述命令......

 Added 34 options
 Initializing module ipv6
 Initializing module tcp
 Finalizing module tcp
 Finalizing module ipv6
 Final packet data:
 60 00 00 00   `...
 /*

  here other packet 
  contents gets printed

  */

 7D 62 00 00   }b..
 61 62 63 64   abcd
 Sent 64 bytes to 2001::200
 Freeing module ipv6
 Freeing module tcp

当我通过命令行执行php脚本时......

[root@udit-pc]# php test.php
Freeing module tcp

hellohi被打印,数据包到达2001 :: 200。

但是当我尝试通过浏览器运行php脚本时会出现问题...

 http:://localhost/test.php

hellohi被打印但数据包没有到达其他机器。

 sh: sendip: command not found

同样在这两种情况下,虽然使用详细选项但是直接使用命令verbose选项时,数据包内容不会在终端打印。

我试过很多东西,虽然我觉得他们不会喜欢......

  1. 我将/ usr / local / lib和usr / local / bin添加到PATH变量但没有任何好处。

  2. chmod + s / usr / local / bin / sendip.Sticky bit set但又没有任何好处。

  3. 将/ usr / local / bin / sendip本身粘贴到/ var / www / html文件夹中虽然我已经更改了PATH变量,但正如我所说我只是使用命中n试用得到的线索.....

  4. 有一些输出快照可能会有所帮助......

    [root@cc html]# echo $PATH
    /usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:
    /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin: 
    /usr/X11R6/bin:/root/bin:/usr/local/lib
    
    [root@cc html]# locate sendip
    .....
    /usr/local/bin/sendip
    /usr/local/lib/sendip
    .....
    
     [root@cc bin]# chmod +s sendip
     [root@cc bin]# ls -l sendip
     -rwsrwsrwx 1 apache apache 41071 Sep 26 19:41 sendip
    
     [root@cc bin]# cd /usr/local/lib/
     [root@cc lib]# ls -ld sendip
     drwxrwxrwx 2 root root 4096 Sep 28 22:48 sendip
     [root@cc lib]# chmod +s sendip
     [root@cc lib]# ls -ld sendip
     drwsrwsrwx 2 root root 4096 Sep 28 22:48 sendip
    

    当文件内容改变时.......

     <?php
     echo exec("/usr/bin/sendip ........  2 > &1");
     ?>
    

    然后oputput是:

     [root@cc html]# php test.php
     Freeing module tcp[root@cc html]# 
    

    在浏览器上....      没有错误打印但数据包仍未到达。

    我被困在中间。请告诉我还有什么我宁愿尝试?????? /

4 个答案:

答案 0 :(得分:1)

在PHP调用的shell的路径中是sendip()吗?你没有检查错误条件,所以你可能实际上没有执行sendip,只是得到“没有这样的程序或文件”类型的错误。

不是将exec()'d命令的输出重定向到null,而是将其全部重定向到浏览器,以便您可以看到会发生什么:

echo exec("sendiip yada yada yada 2>&1");

答案 1 :(得分:0)

尝试使用完整路径:

exec("/usr/lib/sendip -v -p ipv6 -6s 2001::100 -p tcp -ts 21 -td 21 2001::200 > /dev/null &");

答案 2 :(得分:0)

服务器很可能没有使用与您正在测试的用户相同的权限运行。

服务器很可能丢弃任何PATH变量。请务必在sendip来电中指定exec的完整路径。

答案 3 :(得分:0)

问题已经解决了,虽然我不能说它完全解决了,但根据我的需要它的工作。

我做的是重新安装sendip,然后设置其粘滞位,然后我将Path变量设置为如上所述。

实际上,该工具默认情况下在/usr/local/lib/sendip文件夹中安装库,并在/usr/local/bin文件夹中安装sendip。

虽然在设置PATH变量后仍然需要在PHP脚本中使用完整路径

/usr/local/bin/sendip -v .....

(我的一个朋友建议我这个..)

我认为PHP Path与Shell PATH有所不同。我需要将sendip粘贴到/usr/bin然后我需要运行updatedb才能设置其粘滞位,如果我不想提到PHP脚本中的完整路径。现在这个命令在PHP脚本中可以正常工作  sendip -v .........

虽然我错了,但这对我来说都很好。

相关问题