替换$ _GET,使其从命令行工作 [英] Replacing $_GET to make it work from command line

查看:114
本文介绍了替换$ _GET,使其从命令行工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有这个小脚本,使得可以检查域名是否是免费的。它从浏览器工作,当你输入check.php?domain = xxxx.com,你看看是否是免费的。

Currently I have this small script that makes it possible to check if a domain name is free. It works from the browser, when you type check.php?domain=xxxx.com and you see if it is free or not.

因为使用$ _GET只有从浏览器而不是从命令行。

Because of $_GET is used it only works from a browser and not from command line.

PHP手册说,我应该使用$ argv或getopt()来实现这一点。我尝试了,但是我的脚本停止工作。

The PHP manual says that I should use $argv or getopt() to achieve this. I have tried it but then my script stops working.

如何使以下代码从命令行工作?

How can the following code be made to work from command line?

<?php
include_once('/home/xxx/API.php');  
$CClient = new XCApi();
$CClient->isAvailable();
$d = $_GET['domain'];
ob_implicit_flush(1);

for ($i = 0; $i < 60000; ++$i) {

$domainResult = $CClient->checkDomainAvailability( new XDomain( $d ) );

if ( $domainResult->getStatus() == "domain_available" ) {
    echo $i . ". Domain " . $d . " is free (checked: " . date("Y-m-d H:i:s") . ")<br />";

    $_GET['domain'] = $d;
    include_once('Register.php');
    exit;

} 
elseif ( $domainResult->getStatus() == "domain_unavailable" ) {
    echo $i . ". Domain " . $d . " is unavailable (checked: " . date("Y-m-d H:i:s") . ")<br />";
}
else {
    echo $i . ". Domain " . $d . " is unknown (checked: " . date("Y-m-d H:i:s") . ")<br />";
}
echo"<pre>";
print_r($domainResult);
echo"</pre>";
}
?>


推荐答案

更改

$d = $_GET['domain'];

到:

$d = $argv[1];

...并在命令行中调用如下:

...and call it at the command line like this:

php /path/to/script.php "www.domaintocheck.com"

这篇关于替换$ _GET,使其从命令行工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆