每当网页加载时,我都会调用PHP脚本。但是,PHP脚本需要运行一个参数(我通常在测试脚本时通过命令行传递该参数)。
当页面加载时,如何在每次运行脚本时传递此参数?
发布于 2012-12-24 12:36:01
$argv[0]; // the script name
$argv[1]; // the first parameter
$argv[2]; // the second parameter
如果你想让所有的脚本运行,而不管你从哪里调用它(命令行或者浏览器),你需要类似于下面这样的东西:
<?php
if ($_GET) {
$argument1 = $_GET['argument1'];
$argument2 = $_GET['argument2'];
} else {
$argument1 = $argv[1];
$argument2 = $argv[2];
}
?>
从命令行chmod 755 /var/www/webroot/index.php
调用并使用
/usr/bin/php /var/www/webroot/index.php arg1 arg2
要从浏览器调用,请使用
http://www.mydomain.com/index.php?argument1=arg1&argument2=arg2
https://stackoverflow.com/questions/9612166
复制相似问题