如果你想的網址無法讀取,你可以編碼每個字符\ XNN轉義序列:
<?php
$arr = array("http://foo.com","http://bar.com","http://baz.com");
$encodedArr = array();
foreach($arr as $url) {
$encodedUrl = '';
for($i = 0; $i < strlen($url); ++$i) {
$encodedUrl .= '\\x'.str_pad(
sprintf('%x', ord($url[$i])),
2, STR_PAD_LEFT);
}
$encodedArr[] = '"'.$encodedUrl.'"';
}
?>
<script type="text/javascript">
var newArr = [ <?php echo implode(',' ,$encodedArr); ?> ];
alert(newArr[0]);
</script>
書面的JavaScript看起來像這樣:
var newArr = [ "\x68\x74\x74\x70\x3a\x2f\x2f\x66\x6f\x6f\x2e\x63\x6f\x6d","\x68\x74\x74\x70\x3a\x2f\x2f\x62\x61\x72\x2e\x63\x6f\x6d","\x68\x74\x74\x70\x3a\x2f\x2f\x62\x61\x7a\x2e\x63\x6f\x6d" ];
alert(newArr[0]);
但會提醒http://foo.com
即使你對它們進行了模糊處理(這是你所能做的),它們可以用JS調試器挖掘出來。 – mario