<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[谁说网络就是没有技术。C语言malloc在获取cookie中的应用。。。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Tue, 27 Nov 2007 08:19:58 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	代码：<br/>注意函数原型及其返回数值：<br/><br/>char* get_Cookie(const char* name)<br/>{<br/> &nbsp; &nbsp; &nbsp; &nbsp;char* cookie=0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;char* p=0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;int &nbsp; len=0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;p = getenv(&quot;HTTP_COOKIE&quot;) ;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;if(!p)<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp;return 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;len = strlen(name);<br/> &nbsp; &nbsp; &nbsp; &nbsp;cookie = (char*)malloc(len+2) ;<br/> &nbsp; &nbsp; &nbsp; &nbsp;sprintf(cookie,&quot;%s=&quot;,name);<br/> &nbsp; &nbsp; &nbsp; &nbsp;len++;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;if (p = strstr(p,cookie))<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;p=p+len ;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;char* p2;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int &nbsp; &nbsp; len2=0;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(p2=strstr(p,&quot;;&quot;))len2=p2-p;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else len2=strlen(p);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(len2&gt;len) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;free(cookie);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cookie=(char*)malloc(len2+1);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;memcpy(cookie,p,len2);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*(cookie+len2)=0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;else<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;free(cookie);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cookie=0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;return cookie;<br/>}<br/><br/>返回的是char* 指针：<br/><br/>我们main函数：<br/><br/>#include &lt;iostream&gt;<br/>int main(){<br/> &nbsp; &nbsp; &nbsp; &nbsp;printf( &quot;Set-Cookie: curentouturl=kkk...; path=/&#92;n&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;Content-type:text/html&#92;n&#92;n&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;//out_url.Format(&quot;%s&quot;, get_Cookie(&quot;curentouturl&quot;));<br/> &nbsp; &nbsp; &nbsp; &nbsp;char *tmp;<br/> &nbsp; &nbsp; &nbsp; &nbsp;tmp =(char*)malloc(1024);<br/> &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;%s&quot;,get_Cookie(tmp));<br/><br/><br/><br/>return 0;<br/><br/>}<br/><br/><br/><br/><br/><br/>
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] 谁说网络就是没有技术。C语言malloc在获取cookie中的应用。。。]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>