PHP使用HTTP 301重定向网址
17:07 , Qizhi
最近把Blog换到了godaddy.com, 直接刷信用卡就可以,比较方便.原有的域名是新网的,不支持URL转接,所以只能在代码里设置跳转.
域名改变后常用的重定向方式有: 301 redirect, 302 redirect.
301 redirect: 301代表永久性转移(Permanently Moved),301重定向是网页更改地址后对搜索引擎友好的最好方法,只要不是暂时搬移的情况,都建议使用301来做转址。
302 redirect: 302代表暂时性转移(Temporarily Moved ).
$the_host = $_SERVER['HTTP_HOST'];
$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
if($the_host != "www.qizhi.me")
{
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.qizhi.me".$request_uri );
}
"Header( "HTTP/1.1 301 Moved Permanently" )"这一句一定要加上,不然跳转时Http Code是302,表示临时跳转.
域名改变后常用的重定向方式有: 301 redirect, 302 redirect.
301 redirect: 301代表永久性转移(Permanently Moved),301重定向是网页更改地址后对搜索引擎友好的最好方法,只要不是暂时搬移的情况,都建议使用301来做转址。
302 redirect: 302代表暂时性转移(Temporarily Moved ).
$the_host = $_SERVER['HTTP_HOST'];
$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
if($the_host != "www.qizhi.me")
{
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.qizhi.me".$request_uri );
}
"Header( "HTTP/1.1 301 Moved Permanently" )"这一句一定要加上,不然跳转时Http Code是302,表示临时跳转.
Dec
26
2009
关于OpenSource及其License
11:12 , Qizhi
我每天都在使用大量的Opensource的软件、代码,甚至修改这些代码。这些代码基本都被作者在授权说明中定义为“free of charge, without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software”. 但是一般要求使用者将授权书保留在源代码中。
今天有位热心人留言指出,我以前的项目中修改别人的代码,并且将包名也改了,情节很严重。在看到留言之后,我认为我的做法是作者的授权书所允许的,但是为了不引起误会,我还是写了封Email通知了他一下。但是我想说的是,这里作者的代码我改了很多,也不止是包名而已。针对我们的产品甚至做了大量的优化工作,后来的海外版本甚至针对FP10做了彻底的大改与优化。但是很遗憾,这些代码不能开源,后来针对FP10的版本也做了特殊的加密,与OpenSource相关的代码包名也已经与公司名无关。
我想在没有文档的前提下,我如何将这些源代码的原始作者所写的授权书放在什么位置呢?编译后的代码中自然是没有的:) 但是我的项目中源代码根目录下会有一个文件夹,包含所有引用了源代码的原作者的授权书。
下面这是一个项目的授权书列表,作为例子:
This software used a list of opensource projects, including:
//---------------------------------------------------------
// Adobe corelib
//---------------------------------------------------------
Copyright (c) 2008, Adobe Systems Incorporated
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Adobe Systems Incorporated nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//---------------------------------------------------------
// Yahoo Astra!
//---------------------------------------------------------
The copyrights to the software code or designs (i.e., excluding any logos or trademarks or service marks of Yahoo! Inc.) written by Yahoo! are licensed under the following terms:
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software”. 但是一般要求使用者将授权书保留在源代码中。
今天有位热心人留言指出,我以前的项目中修改别人的代码,并且将包名也改了,情节很严重。在看到留言之后,我认为我的做法是作者的授权书所允许的,但是为了不引起误会,我还是写了封Email通知了他一下。但是我想说的是,这里作者的代码我改了很多,也不止是包名而已。针对我们的产品甚至做了大量的优化工作,后来的海外版本甚至针对FP10做了彻底的大改与优化。但是很遗憾,这些代码不能开源,后来针对FP10的版本也做了特殊的加密,与OpenSource相关的代码包名也已经与公司名无关。
我想在没有文档的前提下,我如何将这些源代码的原始作者所写的授权书放在什么位置呢?编译后的代码中自然是没有的:) 但是我的项目中源代码根目录下会有一个文件夹,包含所有引用了源代码的原作者的授权书。
下面这是一个项目的授权书列表,作为例子:
This software used a list of opensource projects, including:
//---------------------------------------------------------
// Adobe corelib
//---------------------------------------------------------
Copyright (c) 2008, Adobe Systems Incorporated
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Adobe Systems Incorporated nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//---------------------------------------------------------
// Yahoo Astra!
//---------------------------------------------------------
The copyrights to the software code or designs (i.e., excluding any logos or trademarks or service marks of Yahoo! Inc.) written by Yahoo! are licensed under the following terms:
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
>> 阅读全文
Dec
23
2009
Flex自定义的数据要避免使用uid关键字
23:34 , Qizhi
最近写一个小工具,用Flex开发,发现一些数据在List/DataGrid中显示时,总是只能选中最后一行.最后发现是因为自定义的数据中使用了uid做成员变量.
uid应该是十分常用的字段了,但是Flex框架也使用了这个变量做各组件的id.设置基于List的组件的dataProvider之后,由于uid重名,自然flex会发生一些异常.
相关代码在mx.utils.UIDUtil中:
public static function getUID(item:Object):String
{
var result:String = null;
if (item == null)
return result;
if (item is IUID)
{
result = IUID(item).uid;
if (result == null || result.length == 0)
{
result = createUID();
IUID(item).uid = result;
}
}
else if ((item is IPropertyChangeNotifier) &&
!(item is IUIComponent))
{
result = IPropertyChangeNotifier(item).uid;
if (result == null || result.length == 0)
{
result = createUID();
IPropertyChangeNotifier(item).uid = result;
}
}
else if (item is String)
{
return item as String;
}
else
{
try
{
// We don't create uids for XMLLists, but if
// there's only a single XML node, we'll extract it.
if (item is XMLList && item.length == 1)
item = item[0];
if (item is XML)
{
// XML nodes carry their UID on the
// function-that-is-a-hashtable they can carry around.
// To decorate an XML node with a UID,
// we need to first initialize it for notification.
// There is a potential performance issue here,
// since notification does have a cost,
// but most use cases for needing a UID on an XML node also
// require listening for change notifications on the node.
var xitem:XML = XML(item);
var nodeKind:String = xitem.nodeKind();
if (nodeKind == "text" || nodeKind == "attribute")
return xitem.toString();
var notificationFunction:Function = xitem.notification();
if (!(notificationFunction is Function))
{
// The xml node hasn't already been initialized
// for notification, so do so now.
notificationFunction =
XMLNotifier.initializeXMLForNotification();
xitem.setNotification(notificationFunction);
}
// Generate a new uid for the node if necessary.
if (notificationFunction["uid"] == undefined)
result = notificationFunction["uid"] = createUID();
result = notificationFunction["uid"];
}
else
{
if ("mx_internal_uid" in item)
return item.mx_internal_uid;
if ("uid" in item)
return item.uid;
result = uidDictionary[item];
if (!result)
{
result = createUID();
try
{
item.mx_internal_uid = result;
}
catch(e:Error)
{
uidDictionary[item] = result;
}
}
}
}
catch(e:Error)
{
result = item.toString();
}
}
return result;
}
问题即出在if ("uid" in item) return item.uid; 这一句上:)
uid应该是十分常用的字段了,但是Flex框架也使用了这个变量做各组件的id.设置基于List的组件的dataProvider之后,由于uid重名,自然flex会发生一些异常.
相关代码在mx.utils.UIDUtil中:
public static function getUID(item:Object):String
{
var result:String = null;
if (item == null)
return result;
if (item is IUID)
{
result = IUID(item).uid;
if (result == null || result.length == 0)
{
result = createUID();
IUID(item).uid = result;
}
}
else if ((item is IPropertyChangeNotifier) &&
!(item is IUIComponent))
{
result = IPropertyChangeNotifier(item).uid;
if (result == null || result.length == 0)
{
result = createUID();
IPropertyChangeNotifier(item).uid = result;
}
}
else if (item is String)
{
return item as String;
}
else
{
try
{
// We don't create uids for XMLLists, but if
// there's only a single XML node, we'll extract it.
if (item is XMLList && item.length == 1)
item = item[0];
if (item is XML)
{
// XML nodes carry their UID on the
// function-that-is-a-hashtable they can carry around.
// To decorate an XML node with a UID,
// we need to first initialize it for notification.
// There is a potential performance issue here,
// since notification does have a cost,
// but most use cases for needing a UID on an XML node also
// require listening for change notifications on the node.
var xitem:XML = XML(item);
var nodeKind:String = xitem.nodeKind();
if (nodeKind == "text" || nodeKind == "attribute")
return xitem.toString();
var notificationFunction:Function = xitem.notification();
if (!(notificationFunction is Function))
{
// The xml node hasn't already been initialized
// for notification, so do so now.
notificationFunction =
XMLNotifier.initializeXMLForNotification();
xitem.setNotification(notificationFunction);
}
// Generate a new uid for the node if necessary.
if (notificationFunction["uid"] == undefined)
result = notificationFunction["uid"] = createUID();
result = notificationFunction["uid"];
}
else
{
if ("mx_internal_uid" in item)
return item.mx_internal_uid;
if ("uid" in item)
return item.uid;
result = uidDictionary[item];
if (!result)
{
result = createUID();
try
{
item.mx_internal_uid = result;
}
catch(e:Error)
{
uidDictionary[item] = result;
}
}
}
}
catch(e:Error)
{
result = item.toString();
}
}
return result;
}
问题即出在if ("uid" in item) return item.uid; 这一句上:)
Dec
21
2009
Blog搬家,离开大局域网
20:23 , Qizhi
Dec
20
2009
Flash程序员的成长之路
00:16 , Qizhi
这个标题看着很唬人.我作为一名做了开发,但没几年的新人,也只是说说这几年的感慨而已.其实我还想去掉"Flash"这个定语(是不是定语?),万不要将自己限定在"Flash"这狭窄的框架之中. 技术界日新月异,作为一名合格的程序员,我想每个人都应该具备一个基本素质,那就是坚持上进,坚持学习的能力.问问自己,最近在看什么书?这是更大的大话,不表.
Flash程序员也是程序员.是程序员就必须得掌握:数据结构.这是大厦的基石.程序=算法+数据结构,这是老师第一节课就教给我们的.讲算法与数据结构的经典书非常多,拿来一本深入研读,必将获益不浅.哪怕在已经拥有多年的开发经验,回头再翻一翻这些书籍,又会有不同的理解.
算法和数据结构太过投入的人很容易陷入到性能的泥淖中,这和看多了设计模式容易造成模式的滥用是一个道理.我们很容易将最近看到的,学到的东西套进我们最近在写的项目中去.随着硬件的升级换代,很多以往的优化技术已经不是那么必要.比如游戏渲染,逻辑运算需要在高FPS下运行,此时就可打破面向对象的一些原理,以期最佳的性能; GUI模块于性能牵扯不大,牺牲一些性能去换取程序的可维护性,可扩展性就很必要.在这个时候,借鉴一些前人总结的经验就很必要,设计模式,项目管理一些书籍就很适合阅读.
说起来,不论是算法,数据结构,还是设计模式,掌握C++或者Java都是很有必要的,他们的地位类似于IT界里的标准语言,Flash Actionscript只能算是一门小小的方言.要走进更大更广阔的天地,更自由的与人交流,假如不掌握标准,那岂不是沟通不便,痛苦不堪?如若不走出Flash,那又岂不是夜郎自大,画地为牢? 这世界上每一门语言都值得我们尊敬,学习.风水轮流转,谁能想到几年前被拿做奇门特效的Javascript今天在RIA发挥出如此耀眼的光芒,它的一些特性甚至影响到现代的很多静态语言.了解其他语言将为我们的编程思想和方法起到莫大的启示和开拓作用.
做到了这些,也仅仅是做到掌握一门工具而已.说白了,就是熟练工.一名普通的应届生只要肯吃苦,上进,好学,通过一些项目几个月到一年就可以做到,这也是我对初级程序员的定义.掌握了一门华丽的工具其实不是最重要的.我想,仅仅就游戏程序员细分下来,人工智能,网络,图形学,任选一门钻研下去这才是未来.假如这些学科里都找不到自己能学下去的理由,那几年之后,还能保住当初作为初级程序员的那些优势么?
PS.
假如要做架构师...我想架构师也是程序员,只不过是面向系统和业务的程序员.
Flash程序员也是程序员.是程序员就必须得掌握:数据结构.这是大厦的基石.程序=算法+数据结构,这是老师第一节课就教给我们的.讲算法与数据结构的经典书非常多,拿来一本深入研读,必将获益不浅.哪怕在已经拥有多年的开发经验,回头再翻一翻这些书籍,又会有不同的理解.
算法和数据结构太过投入的人很容易陷入到性能的泥淖中,这和看多了设计模式容易造成模式的滥用是一个道理.我们很容易将最近看到的,学到的东西套进我们最近在写的项目中去.随着硬件的升级换代,很多以往的优化技术已经不是那么必要.比如游戏渲染,逻辑运算需要在高FPS下运行,此时就可打破面向对象的一些原理,以期最佳的性能; GUI模块于性能牵扯不大,牺牲一些性能去换取程序的可维护性,可扩展性就很必要.在这个时候,借鉴一些前人总结的经验就很必要,设计模式,项目管理一些书籍就很适合阅读.
说起来,不论是算法,数据结构,还是设计模式,掌握C++或者Java都是很有必要的,他们的地位类似于IT界里的标准语言,Flash Actionscript只能算是一门小小的方言.要走进更大更广阔的天地,更自由的与人交流,假如不掌握标准,那岂不是沟通不便,痛苦不堪?如若不走出Flash,那又岂不是夜郎自大,画地为牢? 这世界上每一门语言都值得我们尊敬,学习.风水轮流转,谁能想到几年前被拿做奇门特效的Javascript今天在RIA发挥出如此耀眼的光芒,它的一些特性甚至影响到现代的很多静态语言.了解其他语言将为我们的编程思想和方法起到莫大的启示和开拓作用.
做到了这些,也仅仅是做到掌握一门工具而已.说白了,就是熟练工.一名普通的应届生只要肯吃苦,上进,好学,通过一些项目几个月到一年就可以做到,这也是我对初级程序员的定义.掌握了一门华丽的工具其实不是最重要的.我想,仅仅就游戏程序员细分下来,人工智能,网络,图形学,任选一门钻研下去这才是未来.假如这些学科里都找不到自己能学下去的理由,那几年之后,还能保住当初作为初级程序员的那些优势么?
PS.
假如要做架构师...我想架构师也是程序员,只不过是面向系统和业务的程序员.
Nov
16
2009




