{"id":336,"date":"2009-07-02T17:48:50","date_gmt":"2009-07-02T20:48:50","guid":{"rendered":"http:\/\/wordpress.matbra.com\/?p=336"},"modified":"2010-07-28T16:59:30","modified_gmt":"2010-07-28T19:59:30","slug":"estatisticas-no-seu-tinyurl","status":"publish","type":"post","link":"https:\/\/wordpress.matbra.com\/en\/2009\/07\/02\/estatisticas-no-seu-tinyurl\/","title":{"rendered":"Statistics on your URL Shortener."},"content":{"rendered":"<p>Hello<\/p>\n<p>A few weeks ago I showed you <a href=\"http:\/\/wordpress.matbra.com\/2009\/05\/09\/criando-seu-proprio-tiny-url\/\">how to create your own URL-Shortener<\/a>. I decide to improve it, creating a simple system to control the number of access<\/p>\n<p>First of all you need to add some tables to your data base: <\/p>\n<p>[code lang=&#8221;sql&#8221;]CREATE TABLE access (<br \/>\n  aid INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,<br \/>\n  urls_uid INTEGER UNSIGNED NOT NULL,<br \/>\n  information_iid INTEGER UNSIGNED NOT NULL,<br \/>\n  date DATE NULL,<br \/>\n  PRIMARY KEY(aid),<br \/>\n  INDEX access_FKIndex1(information_iid),<br \/>\n  INDEX access_FKIndex2(urls_uid)<br \/>\n);<\/p>\n<p>CREATE TABLE information (<br \/>\n  iid INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,<br \/>\n  ip VARCHAR(255) NULL,<br \/>\n  PRIMARY KEY(iid)<br \/>\n);[\/code]<\/p>\n<p>After this you should do a modification in your function-little-url.php in the function take_url($url):<\/p>\n<p>[code lang=&#8221;php&#8221;]function take_lurl($lurl) {<br \/>\n\tglobal $link;<br \/>\n\t$q = &#8220;SELECT * FROM `urls` WHERE `unique_chars` = &#8216;&#8221;.$lurl.&#8221;&#8216;&#8221;;<br \/>\n\t$r = mysql_query($q, $link); \/\/ Realiza consulta.<br \/>\n\tif(mysql_num_rows($r)>0) {<br \/>\n\t\t $info = mysql_fetch_array($r);<br \/>\n\t\t $url = $info[&#8220;url&#8221;]; \/\/ Pega endere\u00e7o real<br \/>\n\t\t $uid = $info[&#8220;uid&#8221;]; \/\/ Pega ID do endere\u00e7o<br \/>\n\t\t $ip = $_SERVER[&#8216;REMOTE_ADDR&#8217;]; \/\/ Pega IP do usu\u00e1rio<br \/>\n\t\t $qr = &#8220;select iid from `information` where ip = &#8216;&#8221;.$ip.&#8221;&#8216;&#8221; ;<br \/>\n\t\t $rr = mysql_query($qr, $link);  \/\/ Procura se este IP j\u00e1 est\u00e1 no banco de dados<br \/>\n\t\t if(mysql_num_rows($rr)>0) { \/\/ Caso esteja insere somente um acesso novo proveniente deste IP<br \/>\n\t\t\t$iid = mysql_result($rr,0,&#8221;iid&#8221;);<br \/>\n\t\t\tmysql_query(&#8220;INSERT INTO `access` (urls_uid,information_iid,date) values (&#8220;.$uid.&#8221;, &#8220;.$iid.&#8221;, now())&#8221;, $link);<br \/>\n\t\t } else { \/\/ Caso n\u00e3o esteja, cria um registro com este IP e ap\u00f3s cria um acesso.<br \/>\n\t\t\t$qr = mysql_query(&#8220;INSERT INTO `information` (ip) values (&#8216;&#8221;.$ip.&#8221;&#8216;)&#8221;, $link);<br \/>\n\t\t\t$iid = mysql_insert_id($qr);<br \/>\n\t\t\tmysql_query(&#8220;INSERT INTO `access` (urls_uid,information_iid,date) values (&#8220;.$uid.&#8221;, &#8220;.$iid.&#8221;, now())&#8221;, $link);<br \/>\n\t\t }<br \/>\n\t} else {<br \/>\n\t\techo &#8220;Sorry, link not found!&#8221;;<br \/>\n\t}<br \/>\n\treturn $url;<br \/>\n}[\/code]<\/p>\n<p>In this System there is a table with IPs that already accessed\tsome URL, when a URL is accessed it verify the IP, if it is on the table just create an access to this IP in the new address. Otherwise, add the IP and create the access to the address.<\/p>\n<p><a href=\"http:\/\/wordpress.matbra.com\/?attachment_id=351\">How to create a URL-Shortener with Statistics<\/a><\/p>\n<p>Matheus<\/p>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>Hello A few weeks ago I showed you how to create your own URL-Shortener. I decide to improve it, creating a simple system to control&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/wordpress.matbra.com\/en\/2009\/07\/02\/estatisticas-no-seu-tinyurl\/\">Continue reading<span class=\"screen-reader-text\">Statistics on your URL Shortener.<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[78,69],"tags":[11,9,80,325,323,13,79],"class_list":["post-336","post","type-post","status-publish","format-standard","hentry","category-mysql","category-php","tag-como-fazer","tag-howto","tag-little-url","tag-mysql","tag-php","tag-programacao","tag-tinyurl","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/psjGE-5q","_links":{"self":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts\/336","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/comments?post=336"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts\/336\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/media?parent=336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/categories?post=336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/tags?post=336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}