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