【发布时间】: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>
【问题讨论】:
-
是的,我想是的。但是您可以在浏览器中自行尝试。 首先,转到agent.lionair.co.id/lionairagentsportal/CaptchaGenerator.aspx。它不会显示任何东西。 第二,转到agent.lionair.co.id/lionairagentsportal/default.aspx并打开新标签agent.lionair.co.id/lionairagentsportal/CaptchaGenerator.aspx。图像验证码将在那里。 :真的很好奇:
-
我确信这绝对是关于 cookie 的。但是我怎样才能在我的表格上显示图像验证码呢?找到它应该很辛苦。
标签: php asp.net cookies captcha