0

我想从https://agent.lionair.co.id/lionairagentsportal/CaptchaGenerator.aspx获取图像验证码。

我不明白。

但是,如果我在打开https://agent.lionair.co.id/lionairagentsportal/CaptchaGenerator.aspx之前打开一个带有 url https://agent.lionair.co.id/lionairagentsportal/default.aspx的新标签,则图像是显示。

我只是对https://agent.lionair.co.id/lionairagentsportal/CaptchaGenerator.aspx感到好奇。如果我已经打开https://agent.lionair.co.id/lionairagentsportal/default.aspx,为什么我无法打开它。

我已经尝试过这段代码,但不幸的是我失败了。图像仍然没有显示出来。

<?php

//The curl_init() will initialize a new session and return a CURL handle.
//curl_exec($ch) This function should be called after you initialize a CURL session and     all the options for the session are set. Its purpose is simply to execute the predefined CURL session (given by the ch). 
//curl_setopt( $ch, option, value) Set an option for a CURL session identified by the ch parameter. option specifies which option to set, and value specifies the value for the option given.

$url = "https://agent.lionair.co.id/LionAirAgentsPortal/default.aspx"; // From URL to get webpage contents.
$cookie_file_path = "/opt/lampp/htdocs/curl-examples/cookieFolder/cook";

$ch = curl_init();  // Initialize a CURL session.
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);  // Return Page contents.
curl_setopt($ch, CURLOPT_URL, $url);  // Pass URL as parameter.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); // Tempat menaruh cookies.
$html = curl_exec($ch);  // grab URL and pass it to the variable.

$ch = curl_init();  // Initialize a CURL session.
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);  // Return Page contents.
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);  // Karena keluarannya gambar, maka di-    set binary = true.
curl_setopt($ch, CURLOPT_URL, "https://agent.lionair.co.id/LionAirAgentsPortal/CaptchaGenerator.aspx");  // Pass URL as parameter.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); // Tempat cookies di mana cookies mana yang mau digunakan.

$gambar = curl_exec($ch);  // grab URL and pass it to the variable.
curl_close($ch);  // close curl resource, and free up system resources.

?>
<html>
<head>

</head>
<body>
    <form action="https://agent.lionair.co.id/LionAirAgentsPortal/default.aspx" name="form1" method="post">
        <label for="txtLoginName">Username: </label>
        <input type="text" name="txtLoginName" />
        <br/>
        <label for="txtPassword">Password: </label>
        <input type="password" name="txtPassword" />
        <br/>
        <img src="data:image/jpeg;base64,<?php echo $gambar; ?>" />
        <br/>
        <label for="CodeNumberTextBox">Captcha: </label>
        <input type="text" name="CodeNumberTextBox" />
        <br/>
        <input type="submit" value="otentikasi" />
    </form>
</body>

4

4 回答 4

2

CAPTCHA 生成器在会话中定义 CAPTCHA,该会话仅由实际页面定义。这是一种非常标准的做法,可以提供一种生成 CAPTCHA 的方法。

如果图像生成器负责生成 CAPTCHA,那么您将遇到竞争条件,在提交页面之前看到的不一定是真正的 CAPTCHA 值。此外,Firebug 和 Chrome 的开发者工具等一些开发者工具可能会在内部加载图像,这会在用户不知情的情况下更新验证码。如果图像生成器也创建 CAPTCHA 值,它只会导致更多的混乱。

于 2012-09-30T02:19:40.197 回答
1

这很容易.. 添加此代码:

$ImageCaptcha=base64_encode($gambar);

在“$gambar = curl_exec($ch);”之后

然后更改您的代码: echo $gambar;

回声 $ImageCaptcha;

于 2014-08-08T07:44:50.623 回答
1

您可以在包含 default.aspx 页面的页面上使用透明 iframe。这样,服务器会认为他需要为 default.aspx 页面提供服务,并将在客户端上设置会话 cookie。稍后,当您尝试访问 CaptchaGenerator.aspx 页面时,您将收到响应,因为会话 cookie 将存在于客户端 cookie 存储中。

<iframe src ="https://agent.lionair.co.id/LionAirAgentsPortal/default.aspx" style="widht:0px;height:0px"/>

您可能希望等待 iframe 加载并完成 cookie 创建过程,然后再尝试包含图像,这可以使用 Java 脚本在客户端完成。

希望我能帮上忙。

于 2012-09-30T05:58:19.257 回答
0

改变: curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);

用这个: $cookie="ASP.NET_SessionId="."$cookieValue"; 改变($ch, CURLOPT_COOKIE,$cookie);

它对我有用,但你需要努力在 $url 上获得 cookievalue 希望这有帮助..

于 2012-12-03T19:01:07.737 回答