這個PHP允許用戶使用二進制或純文本的URL提交表單。該URL然後轉換爲純文本,我使用cURL加載響應,然後將其轉換回二進制。如果你想知道,它來自二進制翻譯器,它可以翻譯文本 - >二進制和二進制 - >文本,但也接受URL。cURL沒有設置URL
問題:您可以看到二進制URL被轉換爲文本,然後傳遞給cURL。明文值存儲在$newtext
中。我可以確認binaryToText()
的確如我所做的一些調試所宣傳的那樣工作。純文本URL(請參閱if語句的else
部分)已成功設置,但轉換後的二進制文件不是。
實例
例如$text = "http://google.co.uk";
(isBinary($text) == false
)
curl_setopt($ch, CURLOPT_URL, $text);
< - 這適用
例如$text = "01101000011101000111010001110000001110100010111100101111011001110110111101101111011001110110110001100101001011100110001101101111001011100111010101101011"
(同谷歌URL) (isBinary($text) == true
)
$newtext = binaryToText($text);
curl_setopt($ch, CURLOPT_URL, $newtext);
echo curl_error($ch);
- >輸出 「沒有URL集!」
某處存在這個問題......雖然我看不到它。
代碼
$text = $_POST["text"];
if(startsWith($text, "http://") || startsWith($text, "https://") || startsWith($text, textToBinary("http://")) || startsWith($text, textToBinary("https://"))) {
// URL - accepts binary (prefered), or plain text url; returns binary.
$ch = curl_init();
if(isBinary($text)) {
$newtext = binaryToText($text);
curl_setopt($ch, CURLOPT_URL, $newtext);
} else {
curl_setopt($ch, CURLOPT_URL, $text);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "MY USERAGENT");
if(isset($_GET["r"])) curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result=curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
echo textToBinary($result);
} else if...
功能
function isBinary($input) {
return !preg_match('/[^(0|1)]/', $input); // contains nothing but 0 and 1
}
function binaryToText($input) {
$return = '';
$chars = explode("\n", chunk_split(str_replace("\n", '', $input), 8));
$_I = count($chars);
for($i = 0; $i < $_I; $return .= chr(bindec($chars[$i])), $i++);
return $return;
}
編輯:中$newtext
輸出包含在此輸出:
text: 01101000011101000111010001110000001110100010111100101111011001110110111101101111011001110110110001100101001011100110001101101111001011100111010101101011
newtext: http://google.co.uk
No URL set!00000000
從這:
if(isBinary($text)) {
echo "text: ".$text."\n";
$newtext = binaryToText($text);
echo "newtext: ".$newtext."\n";
curl_setopt($ch, CURLOPT_URL, $newtext);
} else {
curl_setopt($ch, CURLOPT_URL, $text);
}
檢查'$ newtext = binaryToText($ text)' – user3791372
的值嘿,我加了'$ newtext'的輸出,就像它從echo中看到的那樣(請參閱我的答案底部的編輯) –