【问题标题】:Weird Captcha. How it works?奇怪的验证码。这个怎么运作?
【发布时间】:2012-09-21 09:42:30
【问题描述】:

我想从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>

【问题讨论】:

标签: php asp.net cookies captcha


【解决方案1】:

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

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

【讨论】:

  • 那么,我怎样才能得到图像?因为我需要的是在我的表单中替换的图像,如我上面的代码所示。 :'(
  • 老实说,我不知道。您的代码已经在处理收到的 cookie,所以我只能猜测他们通过需要 JavaScript 或类似的客户端来强化他们的 CAPTCHA 针对服务器到服务器(非人类)请求。
  • jimp 我已经删除了涉及萤火虫的代码。图像验证码仍未显示。今晚对我来说似乎是一场噩梦:'(
  • 是的,我在那里看到了更复杂的 javascript。它们被命名为“validation”、“validationGroup”、“Page_ClientValidate”等。您可以在agent.lionair.co.id/LionAirAgentsPortal/… 看到它
【解决方案2】:

您可以在包含 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 脚本在客户端完成。

希望我能帮上忙。

【讨论】:

  • 非常感谢,Uri。我会试一试。如果这种方式可行,我会在这里报告。干杯!!!
  • 我在等待 iframe 事件 onLoad 触发时遇到问题。我在 jquery 中使用 load() 函数,但它根本没有被触发。我使用了 ready() 函数,但它在 iframe 加载之前被触发。
  • @GangsarSwaPurba 我认为您可以在以下答案中找到解决方案:dynamic-iframe-onload-not-firing Long live stackoverflow :)
【解决方案3】:

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

有了这个: $cookie="ASP.NET_SessionId="."$cookieValue"; 更改为($ch, CURLOPT_COOKIE,$cookie);

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

【讨论】:

    【解决方案4】:

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

    $ImageCaptcha=base64_encode($gambar);

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

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

    回显 $ImageCaptcha;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-29
      • 1970-01-01
      • 1970-01-01
      • 2021-01-23
      相关资源
      最近更新 更多