这个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中看到的那样(请参阅我的答案底部的编辑) –