-1

我需要编写一个返回“有效”或“无效参数”的 PHP 脚本

  • 表格网址:http ://www.gpsyeah.com/Login.aspx
  • 账号:istartekdemo
  • 密码:123456

    <?php
    $url = 'http://www.gpsyeah.com/Login.aspx';
    $postfields = array(
    'txtUserName' => 'istartekdemo',
    'txtAccountPassword' => '123456',
    'btnLoginAccount' => '1'
    );
    
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_COOKIESESSION, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
    
    $return = curl_exec($curl);
    echo '<pre>';
    print_r($return);
    echo '</pre>';
    curl_close($curl);
    
    if (!preg_match('#Incorrect#i', $return))
    {
    echo 'VALID';
    }
        else
    {
    echo 'INVALID';
    }
    ?>
    

错误通知使用 Javascript:Alert 显示。那么如何远程检查登录?

4

1 回答 1

0

我稍微修改了你的代码:

<?php
$url = 'http://www.gpsyeah.com/Login.aspx';
$postfields = array(
'txtUserName' => 'istartekdemo',
'txtAccountPassword' => '123456',
'btnLoginAccount' => '1'
);

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);

$return = curl_exec($curl);

curl_close($curl);

if (!preg_match('#loginFaild#i', $return))
{
echo 'VALID';
}
    else
{
echo 'INVALID';
}

?>

如果您查看原始站点http://www.gpsyeah.com/Login.aspx的源代码,当您的身份验证失败时,在代码中它会在第 180 行显示:

<script type="text/javascript">
//<![CDATA[
loginFaild()//]]>
</script>
</form>

现在脚本显示消息 INVALID。

于 2013-09-13T13:03:49.563 回答