<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>邮莓博客~喜爱黑莓 &#187; onclink事件</title>
	<atom:link href="http://mailberry.com.cn/sosel2/onclink%e4%ba%8b%e4%bb%b6/feed/" rel="self" type="application/rss+xml" />
	<link>http://mailberry.com.cn</link>
	<description>Love BlackBerry</description>
	<lastBuildDate>Sun, 05 Feb 2012 11:35:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>简单实现广告链接点击统计，免onclink事件</title>
		<link>http://mailberry.com.cn/2009/11/link-linkdata/</link>
		<comments>http://mailberry.com.cn/2009/11/link-linkdata/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 16:26:24 +0000</pubDate>
		<dc:creator>sosel</dc:creator>
				<category><![CDATA[教程]]></category>
		<category><![CDATA[onclink事件]]></category>
		<category><![CDATA[点击统计]]></category>

		<guid isPermaLink="false">http://mailberry.com.cn/2009/11/link-linkdata</guid>
		<description><![CDATA[最近接手香港淘1站：http://www.tao1shop.com，要改一些模板，添加一些淘客内容，还有想实现点击了广告后，可以统计起来，知道有多少人点击，这样可以知道有多少人对这类广告感兴趣！

   大家都知道现在在线统计的免费网站多的是！但没有针对某个连接做点击统计！为了实现链接点击统计，就百度了一下！很多人都用onclink触发事件来实现，但好像实现起来很麻烦，就跟师傅聊了一下,希望再次得到他的帮助，还好他最近不是很忙，很快就帮我搞定了这功能！在此特谢师傅浪魂的帮助。。。。。。。。。]]></description>
			<content:encoded><![CDATA[<p>&#160;&#160; 最近接手香港淘1站：<a href="http://www.tao1shop.com">http://www.tao1shop.com</a>，要改一些模板，添加一些淘客内容，还有想实现点击了广告后，可以统计起来，知道有多少人点击，这样可以知道有多少人对这类广告感兴趣！</p>
<p>&#160;&#160; 大家都知道现在在线统计的免费网站多的是！但没有针对某个连接做点击统计！为了实现链接点击统计，就百度了一下！很多人都用onclink触发事件来实现，但好像实现起来很麻烦，就跟师傅聊了一下,希望再次得到他的帮助，还好他最近不是很忙，很快就帮我搞定了这功能！在此特谢师傅<strong>浪魂</strong>一直以来的帮助！</p>
<p>&#160;&#160; 实现这功能只要用到两个文件，一个PHP文件和一个txt文件，PHP调用相关函数写入txt文件中，这样免去了写数据库那些麻烦！</p>
<p>PHP文件名为：link.php 代码如下</p>
<p>&lt;?php   <br />$id = trim($_GET['id']);    <br />if ($id) {    <br />&#160;&#160;&#160; $links = json_decode(sreadfile(&#8216;linkdata.txt&#8217;), true);    <br />&#160;&#160;&#160; if ($links[$id]) {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; $links[$id]['click']++;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; swritefile(&#8216;linkdata.txt&#8217;, json_encode($links));    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; header(&quot;location: {$links[$id]['url']}&quot;);    <br />&#160;&#160;&#160; }    <br />} </p>
<p>//获取文件内容   <br />function sreadfile($filename) {    <br />&#160;&#160;&#160; $content = ”;    <br />&#160;&#160;&#160; if(function_exists(&#8216;file_get_contents&#8217;)) {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; @$content = file_get_contents($filename);    <br />&#160;&#160;&#160; } else {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; if(@$fp = fopen($filename, &#8216;r&#8217;)) {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; @$content = fread($fp, filesize($filename));    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; @fclose($fp);    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }    <br />&#160;&#160;&#160; }    <br />&#160;&#160;&#160; return $content;    <br />} </p>
<p>//写入文件   <br />function swritefile($filename, $writetext, $openmod=&#8217;w') {    <br />&#160;&#160;&#160; if(@$fp = fopen($filename, $openmod)) {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; flock($fp, 2);    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; fwrite($fp, $writetext);    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; fclose($fp);    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; return true;    <br />&#160;&#160;&#160; } else {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; return false;    <br />&#160;&#160;&#160; }    <br />}    <br />?&gt;</p>
<p>&#160;</p>
<p>TXT文件名为：linkdata.txt 对应代码</p>
<p>{&quot;1&quot;:{&quot;url&quot;:&quot;http:\/\/www.163.com&quot;,&quot;click&quot;:0},&quot;2&quot;:{&quot;url&quot;:&quot;http:\/\/www.baidu.com&quot;,&quot;click&quot;:0},&quot;3&quot;:{&quot;url&quot;:&quot;http:\/\/www.cnbeta.com&quot;,&quot;click&quot;:0},&quot;4&quot;:{&quot;url&quot;:&quot;http:\/\/www.google.com&quot;,&quot;click&quot;:0}}</p>
<p>&#160;</p>
<p>实现方法：在你要的超连接 &lt;a href&#160;&#160; =&#160;&#160; &quot;<a href="http://www.sina.com.cn">link.php?id=1&quot;</a>&gt;广告&lt;/a&gt;</p>
<p>然后修改linkdata.txt里面对应“1”www.163.com 连接为广告最终连接！</p>
<p>原理：自己想吧~代码就摆在这了！！哈哈！！</p>
<p>&#160;</p>
<p>再次感谢浪魂师傅写的代码！<img alt="" src="http://www.zu14.cn/coolemotion/emotions/zz_1.gif" /></p>
]]></content:encoded>
			<wfw:commentRss>http://mailberry.com.cn/2009/11/link-linkdata/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

