Use Wireshark to capture loopback traffic without a loopback adapter
0If you’ve ever used Wireshark for debugging applications you may have noticed that it only seems to pick up traffic that is actually transmitted over the wire and ignores all traffic sent to your local ip address or localhost. If you want to watch this traffic without having to install a special loopback adapter you can use the following trick.
How to force local traffic to your default gateway
1) Open a command prompt (Run as Administrator for Vista/7)
2) Type ipconfig/all (note your local ip address(es) and default gateway)
3) Type “route add <your ip address> mask 255.255.255.255 <default gateway IP address> metric 1″
This instructs windows to send any requests for your local ip address to your default gateway, which will in turn forward the request back to your machine. Be aware that this route will disappear once you restart your machine unless you include the -p switch after the route command. You may also notice an echo effect if you’re using Wireshark because you see each request and response twice. You can remove this problem by applying the following filter at the top.
ip.src==<default gateway> or ip.dst==<default gateway>
Consider the default gateway as a client trying to reach your machine and all traffic sent to the default gateway as your machine’s response.
To remove the route, type “route delete <the ip address you entered>”.
If you have an application running locally that uses localhost, you can map localhost to the IP address you added a route for. Just don’t forget you mapped localhost to a different IP than 127.0.0.1!
How to map localhost
1) Open notepad (Run as Administrator in Vista/7)
2) Navigate to C:\Windows\System32\drivers\etc\ and open the hosts file (there’s no extension).
3) Add this entry “<the IP address you added a route for> localhost”. Note that the space between the ip address and localhost is a tab.
Now, when your machine tries to send something to localhost, it will resolve to the IP address you added a route for and send its traffic to your default gateway.
(Important!) Remember to unblock the port used for incoming traffic on your machine. Also, if you find that an application you’re using doesn’t seem to send out traffic the way you expect, try flushing the dns cache with ipconfig/flushdns.
PHP 未知类型变量 empty isset 陷阱
3用 empty 检查位置类型的变量时,容易掉进难以察觉的陷阱,请看下面简单的代码,预测一下 3 个 var_dump 的输出:
$mixed_1 = array(); $mixed_2 = 'Nihao'; $bool_1 = empty($mixed_1['1_type']); $bool_2 = empty($mixed_2['2_type']); var_dump($bool_1); var_dump($bool_2); var_dump($mixed_2['2_type']);
为了不影响你的判断,我多空几行,然后对比结果,是否跟你判断的一致。
。
。
。
。
。
。
。
。
。
。
。
。
。
。
公布结果:
bool(true) bool(false) string(1) "h"
后面 2 个结果,是不是有点意外?
导致问题的原因,就是 PHP 会自动把字符串按照数组来处理,并且,当 $mixed 不是严格意义的数组时,对元素的引用 key 会把 key 转换为数字,2_type 转换为数字之后,就是数字 “2″,对应的元素值就是 “h”。
对应的,isset 也会认为 $mixed_2['2_type'] 是存在的。
结论:
在对未知类型的变量做 isset 或 empty 查询时,应同时附加 is_array 等类型检查,才会更安全。
Firefox 网页 光标 闪烁
0最近 Firefox 出现怪异情况:鼠标点击网页,在点击的位置显示光标,并一直闪烁,导致 Home End 等按键都无效。
原来这是 Firefox 的 “特色功能”:Caret Browsing,激活这个功能以后,我们可以使用键盘来选择页面内容。
这个功能的开关是F7,打开Firefox,按一下F7,就会跳出一个对话框:
“Pressing F7 turns Caret Browsing on or off. This feature places a moveable cursor in web pages, allowing you to select text with the keyboard. Do you want to turn Caret Browsing on?”
选择”Yes”开;选择”No”关。
黑色礼物
2滴滴、滴滴。。。无数的报警短信,让手机一直在不停地响着,每响一次,都让我心惊胆战。
我盼望这种煎熬赶紧过去,但这无数的报警短信,排成了长长的队列,一个一个从手机里蹦出来,变成尖刀,插进我的心脏。
页面白了,白了三分钟。
我的世界黑了,不知道黑暗什么时候可以过去。
我坐在座位上,眼睛紧紧地盯着屏幕。
惊魂未定。脑子里一片空白。
我不敢离开座位,我不敢出现在同事面前,我不敢看同事的眼睛。
我不敢离开公司,我不敢出现在路人的视线里,我就像个罪人,似乎全世界的人都变成了受害者,而我是唯一的罪魁祸首。
这一切偏偏发生在 10 月 26 日,我的命运就像一场闹剧。
Yoyo 说:要勇敢面对问题。
恩,我会的。
Iframe Tips ABC
2
通常我们用 js 脚本创建 iframe 时,会这样写:
var iframe = document.createElement('iframe');
之后我们可能会定义 id、name、border 等属性,这些看似简单,其实 IE 与非 IE 浏览器之间、IE 和 IE 高版本之间的迥异,使得 iframe 的相关兼容性操作非常地有文章。
牛A:frameborder
现象:使用 (iframe.frameBorder = 数值) 或(iframe.setAttribute(‘frameborder’,数值)) 在 IE 浏览器下无效
原因:IE 浏览器区分属性名称大小写
解决方法:iframe.setAttribute(‘frameBorder’,’0′) Or iframe.setAttribute(‘frameborder’,’0′,0),兼容所有浏览器。
注:经测试,IE8已经修复此问题
牛B:动态将Form target到iframe
背景:假设现在我们要让一个 Form 表单结果提交到一个 HTML 结构中已存在的 iframe,会这样做:
<form id="form" name="form" target="相应iframe的name:iframeNB" method="post" >
</form>
<iframe name="iframeNB" ></iframe>
OK,什么问题也没有,再假设我们需要提交到脚本动态生成的 iframe 中,会这样做:
<form id="form" name="form" target="iframeNB" method="post" >
</form>
<script>
var iframe = document.createElement('iframe');
iframe.name = 'iframeNB';
...
someParent.appendChild(iframe);
</script>
去 IE 浏览器里试试,你会发现 Form 会在新窗口显示提交结果,Why?
原因:
我为此尝试了很久,结果是IE此前版本不能通过(iframe.name=)这种方式给 iframe 设置 name 值,也就是说生成的 iframe 是没有 name 值的,但却可以 alert 出来,这很诡异;当然,这也并不是没有解决办法。
解决方法,为此我们得为 IE 单独写一行代码:
/*only for ie */
var iframe = document.createElement('<iframe name="iframeNB">');
看到这行代码,我们笑了,这是天大的杯具(喜剧?)~~不管IE有多么搓的问题,他总会有自己一套解决之……
而且这行代码会在其他非 IE 浏览器抛出异常,所以我们可以利用这点来做最终版:
var iframe;
try{
iframe = document.createElement('<iframe name="iframeNB">');
}catch(e){
iframe = document.createElement('iframe');
}
iframe.name = 'iframeNB';
...
someParent.appendChild(iframe);
...
[2009-12-9]补充:最佳实践 – YUI 是如何 creat iframe 的
/**
* @description Creates an iframe to be used for form file uploads. It is remove from the
* document upon completion of the upload transaction.
* @method createFrame
* @private
* @static
* @param {string} optional qualified path of iframe resource for SSL in IE.
* @return {void}
*/
function _createFrame(secureUri){
// IE does not allow the setting of id and name attributes as object
// properties via createElement(). A different iframe creation
// pattern is required for IE.
var frameId = 'yuiIO' + this._transaction_id,io;
if(YAHOO.env.ua.ie){
io = document.createElement('<iframe id="' + frameId + '"name="' + frameId + '" />');
// IE will throw a security exception in an SSL environment if the
// iframe source is undefined.
if(typeof secureUri == 'boolean'){
io.src = 'javascript:false';
}
}else{
io = document.createElement('iframe');
io.id = frameId;
io.name = frameId;
}
io.style.position = 'absolute';
io.style.top = '-1000px';
io.style.left = '-1000px';
document.body.appendChild(io);
YAHOO.log('File upload iframe created. Id is:' + frameId, 'info', 'Connection');
}
这里需要额外注意到的一点是:
// IE will throw a security exception in an SSL environment if the
// iframe source is undefined.
if(typeof secureUri == 'boolean'){
io.src = 'javascript:false';
}
姑且算是牛D吧 =.=!
牛C:iframe.onload
关于 onload 这点大家可以参考怿飞师父的文章:判断 iframe 是否加载完成的完美方法,在此纯引用一次代码:
var iframe = document.createElement("iframe");
iframe.src = "http://www.planabc.net";
if (iframe.attachEvent) {
iframe.attachEvent("onload", function () {
alert("Local iframe is now loaded.");
});
} else {
iframe.onload = function () {
alert("Local iframe is now loaded.");
};
}
document.body.appendChild(iframe);
需要注意到的是:
- IE8也不支持iframe.onload
- Opera两者均可,所以使用此方法会绑定前者
- 即使我们不预设iframe.src = some urls,也会默认执行一次onload事件,可以通过分析 src 规避。
附测试文件:
1.iframe_ie_ugly.html
2.iframe_fixed.html
以上,我认为 ABC 中最牛的就是 B 了,这也是我标题的亮点=.=! 斯密达们认为呢?
上述文字转自 http://blog.silentash.com/2009/12/iframe-tips-abc/,感谢原作者给我提供的巨大帮助。
转载在这里与更多人分享。
IE Bug Javascript
0问题描述:
当 A 标签的文本是 http 开头时,设置 href 属性,会同时以相同的值更新链接文本,反之亦然。
解决方法:
在设置 href 时,在开头添加一个空格 ‘ ‘,即可解决此 bug。
测试 Demo:
http://code.leakon.com/javascript/set_href/set_href.html
注意,只在 IE 下会出现错误。
预期的功能是修改链接的 href 属性。
使用默认的修改方法有 bug,会把链接文本改掉!
0×80040111 NS_ERROR_NOT_AVAILABLE
0Firefox 在处理 Ajax 遇到错误时会报 0×80040111 异常。
在网上查了下,有的说法是,在很短的时间间隔发送了 2 次 Ajax 请求,XMLHttpRequest 的值还没有返回回来就又被请求了一次。
还有一个情况,是我遇到的,在请求成功返回后执行回调函数时,引用了空对象的属性,debug 报错:”null has no properties“。
目前只遇到这 2 种情况,记录备忘。
WinSCP UltraEdit Unix DOS Format
0
用 WinSCP + UltraEdit,可以直接修改服务器上的文件,保存时自动上传到服务器上,用起来很方便。
最近发现个情况,服务器上的文件不管是 DOS 还是 Unix 格式,用 UltraEdit 打开总是显示 DOS 格式,保存后,却都变成了 Unix 格式!
反复检查了 UltraEdit 的设置选项,都没问题,编辑本机文件都是正常的。
后来开始怀疑 WinSCP。
费了好半天劲,终于找到原因,在 Editor 选项中可以设置外部编辑器,然后设置编辑器选项,如顶图所示红框的位置。
意思是,用编辑器传文件强制使用文本方式传输,这就是导致问题的关键点。
把这个选项去掉,打开文件格式可以正确识别,保存后格式也不会全部转换成 Unix 了。
记录 & 分享。
KB927917 IE 报错 解决方法
0在 body 标签内调用 append 方式给 body 增加一个节点,如果此时 body 未加载完,也就是 body 标签还未关闭,IE 将报错:KB927917。
页面错误提示:Unable to modify the parent container element before the child element is closed.
查了下资料,知道了问题的产生原因:
首先是微软的详细解释:http://support.microsoft.com/kb/927917
最后发现其实微软的MSDN上早已列举了解决办法:
http://blogs.msdn.com/ie/archive/2008/04/23/what-happened-to-operation-aborted.aspx
官方给出的解决办法如下:
- Moving your script execution to a function that is invoked after parsing is complete (e.g., onload)
- Adding the defer boolean attribute to the script block (this defers execution of the script content until parsing is complete)
- Limiting your tree modifications to the script-element’s immediate parent
- Moving the location of your script block to a child of the body (this usually solves most problems, while allowing the most flexibility in terms of scenarios).
