<?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>XmasB &#187; Blogg</title>
	<atom:link href="http://xmasb.com/tag/blogg/feed/" rel="self" type="application/rss+xml" />
	<link>http://xmasb.com</link>
	<description>Be spontaneous! You go first.</description>
	<lastBuildDate>Wed, 16 Nov 2011 09:45:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Bloggen fyller 5 år!</title>
		<link>http://xmasb.com/2011/05/21/bloggen-fyller-5-ar/</link>
		<comments>http://xmasb.com/2011/05/21/bloggen-fyller-5-ar/#comments</comments>
		<pubDate>Sat, 21 May 2011 05:42:07 +0000</pubDate>
		<dc:creator>Yngve Thoresen</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Blogg]]></category>
		<category><![CDATA[Gratulerer]]></category>
		<category><![CDATA[Jubileum]]></category>

		<guid isPermaLink="false">http://xmasb.com/?p=1480</guid>
		<description><![CDATA[At denne bloggen skulle bli hele 5 år hadde jeg liten tro på den gang jeg opprettet den. 5 år er altså gått siden første post, klaging på naboen og enkle gleder som vafler på fredag. Bloggen har vært gjennom en mange forandringer på både design og innhold. Design blir man vel aldri helt fornøyd [...]]]></description>
			<content:encoded><![CDATA[<p>At denne bloggen skulle bli hele 5 år hadde jeg liten tro på den gang jeg opprettet den. 5 år er altså gått siden første post, klaging på naboen og enkle gleder som vafler på fredag. Bloggen har vært gjennom en mange forandringer på både design og innhold.</p>
<p>Design blir man vel aldri helt fornøyd med, sev om jeg var nær ved forrige tema. Dessverre skulle det temaet få store problemer når forfatteren oppgraderte, jeg har ihvertfall ikke fått det til å virke som det skal ved senere versjoner. Mitt child-theme, et tema bygget videre på et annet, sluttet også å virke. Innhold er en helt annen sak.De vanligste anbefalinger for å holde på lesere, samt få nye, er å publisere jevnt og holde en rød tråd. Jeg har ikke vært flink til noen av delene, men velger å skylde på en fordobling av familien. Fra to til fire. Slikt sluker tid, som mange sikkert vet. Noen pappablogg ble det aldri, og godt er det.</p>
<p>At frekvensen har gått ned kan også skyldes andre grunner, som flere sosiale medier. <a href="http://www.facebook.com/yngve.thoresen">Facebook</a> har jeg aldri brukt noe særlig, men <a href="http://twitter.com/#!/xmasb">Twitter</a> tok over jobben for for de fleste små poster. En egen <a href="http://yngvethoresen.com/">fotoblogg</a> har ført til at bilder ikke lenger blir publisert her, samtidig som foto har tatt mer av fritiden. Det er posititvt. Jobb spiser også stadig mer av fritiden min. Det er ikke alltid like positivt, men det er mitt eget valg.</p>
<p>Når jeg startet å blogge var vi ikke mange som drev med det. Mange var før meg, men ekstremt mange kom etter. Sett fra media sitt ståsted handler en blogg om å fortelle hva man har på seg, hva man spiser og hvordan katten har det. I takt med eksplosjonen av antallet blogger har leselisten min gått motsatt vei, jeg leser færre blogger enn noensinne. Bortsett fra før jeg begynte å lese blogger da&#8230; (smartass)</p>
<p>Jeg er heller ikke like flink til å kommentere på de bloggene jeg faktisk leser, med den effekten at jeg også får færre kommentarer her. Det er jo egentlig greit nok. Når jeg begynte å blogge var jeg veldig opptatt av statistikk, men dette interesser meg i liten grad i dag.</p>
<p>Så hva er fremtiden til xmasb.com? Aner ikke. Kanskje vil det ta seg opp litt, men det kan også hende jeg flytter den over til yngvethoresen.com. Ulempen da er at fotobloggen er på engelsk, mens jeg egentlig ønsker å ha den skrevne blogg på norsk. Å skrive en kort tekst til et bilde på engelsk går veldig greit. Å skrive lengre poster krever litt mer, og blir da gjerne ikke gjort. <img src='http://xmasb.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://xmasb.com/2011/05/21/bloggen-fyller-5-ar/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Hotlinkere er som oftest fjortiser</title>
		<link>http://xmasb.com/2010/12/02/hotlinkere-er-som-oftest-fjortiser/</link>
		<comments>http://xmasb.com/2010/12/02/hotlinkere-er-som-oftest-fjortiser/#comments</comments>
		<pubDate>Thu, 02 Dec 2010 13:50:20 +0000</pubDate>
		<dc:creator>Yngve Thoresen</dc:creator>
				<category><![CDATA[Geek]]></category>
		<category><![CDATA[Bilder]]></category>
		<category><![CDATA[Blogg]]></category>
		<category><![CDATA[Hotlinking]]></category>
		<category><![CDATA[Tyveri]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://xmasb.com/?p=1403</guid>
		<description><![CDATA[Jeg skrev tidligere en liten innføring i hvordan jeg har stoppet hotlinkere fra å vise bilder liggende på bloggen min. Der beskrev jeg hvordan jeg brukte .htaccess filen for å hindre de jeg la til i listen. Dette fungerer glimrende og har egentlig ingen store ulemper. Jeg oppnår det jeg vil, som altså er å [...]]]></description>
			<content:encoded><![CDATA[<p>Jeg skrev tidligere en liten innføring i hvordan jeg har stoppet hotlinkere fra å vise bilder liggende på bloggen min. Der beskrev jeg hvordan jeg brukte .htaccess filen for å hindre de jeg la til i listen. Dette fungerer glimrende og har egentlig ingen store ulemper. Jeg oppnår det jeg vil, som altså er å hindre uvedkommende i å stjele båndbredden min.</p>
<p>Men det kan bli så mye bedre. Jeg savner nemlig et par ting. Nemlig å se hvilke som blir fanget opp er tungvint, og ikke minst kunne kontrollere tilgang raskt og effektivt basert på data i sanntid.</p>
<p>Eneste måten jeg kan se hvem som snylter på er nemlig å gå gjennom logger, for så å plukke ut de som synder mest (eller bruke fantastisk lang tid på å lete i loggene&#8230;). Og ettersom jeg ønsker å kunne se hvorvidt tiltaket virker (eller bare bidrar til gratis reklame for meg) er det ingen god løsning å lete i logger som kun viser fordeling på måned.</p>
<p>Men det var før. Nå har jeg gjort noen små endringer som fungerer enda bedre. Kan det fungere bedre enn glimrende sier du? Javisst. Følg med.</p>
<p>I den nye versjonen har jeg byttet ut loggfilen med et par tabeller i databasen min. En tabell styrer tilgang og en er for logg. htacces filen er endret til å sende alle forespørsler som ikke er fra eget domene eller et fåtall andre, deriblant bildesøk fra google, til et php script som tar seg kontroll og visning av bilder. Alt som som routes til scriptet logges med nødvendig info.</p>
<p>Tabellen som styrer tilgang har et flagg som forteller om det aktuelle domenet skal få tilgang til bildene. Om domenet ikke ligger i tabellen fra før blir det lagt til, med tilgang. Ønsker jeg å fjerne eller gi tilgang kan jeg når som helst endre dette. Verdien fra denne tabellen brukes for å vise det riktige bildet eller denne <a href="http://xmasb.com/wp-content/uploads/hotlink.jpg">snasne dama</a>.</p>
<p>Tabellen for logging inneholder hver eneste forespørsel som blir gjort med henvisende url, bildets url, domeneid koblet til tilgangstabellen, og hvorvidt tilgang er gitt. Dermed har jeg mulighet til å trekke ut det jeg trenger av statistikk. Og statistikk liker jeg, så det viser jeg med all data jeg har tilgengelig. Jeg har derfor statistikk fordelt på domener, bilder, tilgang, tidspunkt, i topplister og siste treff. IP og denslags logger jeg ikke.</p>
<p>Og hvis noen lurer på overskriften kan jeg fortelle at blogg.no står for brorparten av hotlinkere mot denne bloggen, sammen med et par forum hvor brukere har hotlinket avatar bildet sitt fra bloggen min. De bytter nok ganske snart&#8230;</p>
<p>Se forøvrig mer om <a href="http://www.halolz.com/2008/03/10/hot-link-on-link-action/">hot linking</a> her.</p>
<p><strong>Oppdatering:</strong><br />
Koden for <a href='http://xmasb.com/wp-content/uploads/2010/12/hotlink.txt'>php scriptet er lagt ut</a>. Husk å endre filen til php, samt legge inn server, brukernavn, passord og database. Jeg benytter samme database som for WordPress, men med annet prefix for å skille tilhørighet for tabellene fra hverandre.</p>
<p><strong>PHP (scriptet i filen du finner over):</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'hotlinkimage'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'donthotlink.jpg'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ref_domain'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'referrer'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fullurl'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://'</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// mod_rewrite should have already established that it is a hot-link.</span>
	<span style="color: #666666; font-style: italic;">// This is a double-check. We need to capture the referrer, anyway.</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_REFERER'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'referrer'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_REFERER'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ref_domain'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'referrer'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">,</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'referrer'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// splitting the referrer into a domain part, saves us searching for multiple variations.</span>
	<span style="color: #666666; font-style: italic;">// so long as your host name appears somewhere in the domain part, it's not a hot-link.</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">stristr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ref_domain'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$domain</span> <span style="color: #339933;">=</span> getDomain<span style="color: #009900;">&#40;</span><span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ref_domain'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">allow</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			log_hotlink_to_db<span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'referrer'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fullurl'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			serveImage<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'../'</span><span style="color: #339933;">.</span><span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
			log_hotlink_to_db<span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'referrer'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fullurl'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			serveImage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'hotlinkimage'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
		serveImage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// No url? Redirect them to the main site.</span>
	<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Location: http://&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>En enkel klasse for domene. Kunne godt laget en klasse for referrer også, men er ikke nødvendig.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>46
47
48
49
50
51
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Simple class for domain</span>
<span style="color: #000000; font-weight: bold;">class</span> Domain<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$domain</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$allow</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Logge til db.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>53
54
55
56
57
58
59
60
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//log the attempt to db</span>
<span style="color: #000000; font-weight: bold;">function</span> log_hotlink_to_db<span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #339933;">,</span> <span style="color: #000088;">$referrer</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$allowed</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$db_connection</span> <span style="color: #339933;">=</span> getDBConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$statement</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db_connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO hotlink_log (domain_id, referrer,url,allow) VALUES (?,?,?,?)&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Failed to prepare the statement!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$statement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind_param</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;issi&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$domain</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$referrer</span><span style="color: #339933;">,</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span><span style="color: #000088;">$allowed</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$statement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$statement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Et par funksjoner for å håndtere domener.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> getDomain<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ref_domain</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/^www./i&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$ref_domain</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// WWW. is deprecated anyway...</span>
		<span style="color: #000088;">$ref_domain</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/^www./i&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ref_domain</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$domain</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Domain<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$domain</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$domain</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">domain</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ref_domain</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$domain</span> <span style="color: #339933;">=</span> checkDomain<span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		insertNewDomain<span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$domain</span> <span style="color: #339933;">=</span> checkDomain<span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$domain</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> checkDomain<span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$db_connection</span> <span style="color: #339933;">=</span> getDBConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$statement</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db_connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT id, allow FROM hotlink_access WHERE domain = ?&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Failed to prepare the statement!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$statement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind_param</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;s&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$domain</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">domain</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$statement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$statement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$allow</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$statement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$domain</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$domain</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">allow</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$allow</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$statement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$domain</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> insertNewDomain<span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$db_connection</span> <span style="color: #339933;">=</span> getDBConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$statement</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db_connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO hotlink_access (domain,allow) VALUES (?,1)&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Failed to prepared the statement!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$statement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind_param</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;s&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$domain</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">domain</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$statement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//$statement-&gt;affected_rows</span>
&nbsp;
	<span style="color: #000088;">$statement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Vær så god, her har du et bilde. Håper du blir fornøyd.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> serveImage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span> and <span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'img_type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">end</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strcasecmp</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'img_type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'png'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'img'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefrompng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">imagesavealpha</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'img'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strcasecmp</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'img_type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'jpg'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">||</span> <span style="color: #990000;">strcasecmp</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'img_type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'jpeg'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'img'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromjpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strcasecmp</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'img_type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'gif'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'img'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromgif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">trigger_error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HOTLINK - Image <span style="color: #006699; font-weight: bold;">$url</span> is of unknown type&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">E_USER_ERROR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">//TODO Other file types?</span>
&nbsp;
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Log image not found!</span>
		<span style="color: #990000;">trigger_error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HOTLINK - Image <span style="color: #006699; font-weight: bold;">$url</span> was not found&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">E_USER_ERROR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// send the image to the browser..</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'img_type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'png'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: image/png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'img'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;there was an error. sorry about that...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: image/jpg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imagejpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'img'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;there was an error. sorry about that...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'img'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Skaff en connection til db. Det er her data om server, brukernavn, passord og database skal inn.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>135
136
137
138
139
140
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> getDBConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$db_connection</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> mysqli<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;server&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;database&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Failed to obtain connection to db!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$db_connection</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>Databasetruktur (SQL) er som følger:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> hotlink_access <span style="color: #66cc66;">&#40;</span>
  id <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">DOMAIN</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  allow <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> hotlink_log <span style="color: #66cc66;">&#40;</span>
  id <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  domain_id <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  referrer <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  url <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  allow tinyint<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">TIME</span> <span style="color: #993333; font-weight: bold;">TIMESTAMP</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">CURRENT_TIMESTAMP</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Egentlig er det også en timestamp i access tabellen også, men den trengs strengt tatt ikke da samme data ligger i loggtabellen.</p>
<p>Til slutt den delen som gjør selve redirekten:<br />
<strong>.htaccess filen:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;"># BEGIN Hotlink stopper</span>
<span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
<span style="color: #00007f;">RewriteCond</span> %{HTTP_REFERER} !^$
<span style="color: #00007f;">RewriteCond</span> %{HTTP_REFERER} !^http(s)?://(www\.)?xmasb\. [NC]
<span style="color: #00007f;">RewriteCond</span> %{HTTP_REFERER} !^http(s)?://((.+)\.)?google\.(.+imgres) [NC]
<span style="color: #00007f;">RewriteCond</span> %{HTTP_REFERER} !^http(s)?://((.+)\.)?google\.(.+reader) [NC]
<span style="color: #00007f;">RewriteRule</span> ^(.*)\.(gif|jpe?g|png)$ http://%{HTTP_HOST}/hotlink/hotlink.php?url=$1.$2 [R,NC,L]
<span style="color: #adadad; font-style: italic;"># END Hotlink stopper</span></pre></td></tr></table></div>

<p>Alle request som ikke er direkte på bildene (gif|jpe?g|png), via xmasb, google&#8217;s bildesøk eller google reader blir sendt til scriptet. Scriptet sørger for resten.<br />
Her kan alle tillatte domener legges inn, så det ikke brukes unødig prossesering på tillatte domener. Eksempel på andre domener som kanskje bør ligge her er RSS lesere (Google, Bloglines, Netvibes f.eks) og andre sider for bildesøk. Det fine med denne fremgangsmåten er at det er lett å oppdage disse underveis, uten at de er utestengt i mellomtiden.</p>
<p>Det er lett å bare legge inn Google som tillatt domene i htaccess filen, men husk at det også eksisterer noe som heter sites.google.com. Scriptet får et par treff om dagen derfra.</p>
<p><strong>Oppdatering 2:</strong><br />
Har gjort en liten endring til på scriptet mitt. Ettersom blant annet blogg.no er kraftig overrepresentert i loggene er det like greit å sperre de ute med en gang. Jeg kunne selvsagt gjort dette via htaccess filen, men får å få med loggingen tar jeg de via scriptet likevel. For å gjøre dette har jeg gjort følgende endring i insertNewDomain funksjonen:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>138
139
140
141
142
143
144
145
146
147
148
149
150
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> insertNewDomain<span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #339933;">,</span> <span style="color: #000088;">$allow</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$hotlink</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>anyNeedleInString<span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">domain</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'blockedBaseDomains'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$allow</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$db_connection</span> <span style="color: #339933;">=</span> getDBConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$statement</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db_connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO hotlinkaccess (domain,allow) VALUES (?,?)&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Failed to prepared the statement!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$statement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind_param</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;si&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$domain</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">domain</span><span style="color: #339933;">,</span> <span style="color: #000088;">$allow</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$statement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//$statement-&gt;affected_rows</span>
&nbsp;
	<span style="color: #000088;">$statement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>AnyNeedleInString ser slik ut:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>187
188
189
190
191
192
193
194
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> anyNeedleInString<span style="color: #009900;">&#40;</span><span style="color: #000088;">$haystack</span><span style="color: #339933;">,</span> <span style="color: #000088;">$needle</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$needle</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$search_needle</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">stristr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$haystack</span><span style="color: #339933;">,</span> <span style="color: #000088;">$search_needle</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Og så er det bare å definere en array som inneholder de domener man ikke vil ha med:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$hotlink</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'blockedBaseDomains'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'blogg.no'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'nettby.no'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Her illustrert med blogg.no og nettby.no. Dermed slipper jeg å håndtere de som tilhører diverse plattformer. Smart, ikke sant?</p>
]]></content:encoded>
			<wfw:commentRss>http://xmasb.com/2010/12/02/hotlinkere-er-som-oftest-fjortiser/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Hvor fancy må det være?</title>
		<link>http://xmasb.com/2009/11/03/hvor-fancy/</link>
		<comments>http://xmasb.com/2009/11/03/hvor-fancy/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 08:52:05 +0000</pubDate>
		<dc:creator>Yngve Thoresen</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[Blogg]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Fotoblogg]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://xmasb.com/?p=1201</guid>
		<description><![CDATA[Etter at jeg flyttet fotobloggen min til nytt domene begynte jeg også å se meg om etter nye løsninger for å presentere bildene mine på. Jeg har ingen planer om å forlate WordPress-plattformen, men en endring av tema kunne være en mulighet. Dermed var det å kikke gjennom temaer på andre lignende sider, i tillegg [...]]]></description>
			<content:encoded><![CDATA[<p>Etter at jeg flyttet fotobloggen min til nytt <a href="http://yngvethoresen.com">domene</a> begynte jeg også å se meg om etter nye løsninger for å presentere bildene mine på. Jeg har ingen planer om å forlate WordPress-plattformen, men en endring av tema kunne være en mulighet. Dermed var det å kikke gjennom temaer på andre lignende sider, i tillegg til de utallige nettsider som presenterer temaer for WordPress. En ting jeg fort la merke til er den utstrakte bruken av Flash og JavaScript, spesielt sistnevnte.</p>
<p>Personlig bruker jeg en egen addon i Firefox for å hindre at JavaScript og Flash ikke blir vist uten at jeg tillater det (<a href="http://noscript.net/">NoScript</a>). Dette betyr ofte noen ekstra klikk i surfingen, men fjerner også det meste av reklame og ikke minst ondsinnet kode. I starten var det litt irriterende, men nå tenker jeg ikke over det lenger. Det er blitt en naturlig del av surfingen. De aller fleste sider trenger ingen ekstra klikk, mens andre har kjørende kode fra en hel haug med nettsider. Et eksempel på en nettside med irriterende reklame jeg slipper er VG, som har en del bevegende reklame her og der. Standard er da at kode fra basefarm (serveren som kjører reklamen til VG) ikke kjøres hos meg, og nettsiden er fullstendig statisk og uten forstyrrende elementer. Med unntak av elendige artikler og selvpromotering selvsagt.</p>
<p>Noen nettsider som tydeligvis har hengt seg veldig på utstrakt bruk av fancy kode i form av Flash eller JavaScript er fotosider. Spesielt hjemmesidene til fotografer, enten det dreier seg om fotoblogger eller gallerier. En ting er ihvertfall klart: den mer erfarne fotografen bruker mest Flash. Dette igjen kan se ut til å føre med seg at man skal, og må, bruke Flash for å ha en fotoside. Som igjen resulterer i et stort antall veldig flotte sider, men som er utrolig tungvinte å lese.</p>
<p>Det trenger ikke være sånn. Noen av de beste galleriene jeg vet om på nett bruker ikke hverken Flash eller JavaScript. Det er ingenting som flyr over skjermen, ingen lyder, og man trenger ikke ha sett Tom Cruise leke seg med teknologi i Minority Report for å forstå hvordan man skal orientere seg på nettsiden.</p>
<p>For ordens skyld har jeg testet mine egne nettsider uten tillatelser fra NoScript, og det har ingen påvirking.</p>
]]></content:encoded>
			<wfw:commentRss>http://xmasb.com/2009/11/03/hvor-fancy/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Jeg flytter!</title>
		<link>http://xmasb.com/2009/09/21/jeg-flytter/</link>
		<comments>http://xmasb.com/2009/09/21/jeg-flytter/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 12:27:53 +0000</pubDate>
		<dc:creator>Yngve Thoresen</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Blogg]]></category>
		<category><![CDATA[Fotoblogg]]></category>

		<guid isPermaLink="false">http://xmasb.com/?p=1174</guid>
		<description><![CDATA[Som du kanskje har fått med deg har jeg to blogger gående om dagen; XmasB (denne) og Captured Echoes. &#171;Gående&#187; er kanskje å ta i litt, for jeg har ikke akkurat produsert jevnt og trutt i det siste. Denne bloggen, i skrivende stund på XmasB er en norsk blogg som jeg har hatt ganske lenge [...]]]></description>
			<content:encoded><![CDATA[<p>Som du kanskje har fått med deg har jeg to blogger gående om dagen; <a href="http://xmasb.com">XmasB</a> (denne) og <a href="http://capturedechoes.com">Captured Echoes</a>. &laquo;Gående&raquo; er kanskje å ta i litt, for jeg har ikke akkurat produsert jevnt og trutt i det siste.</p>
<p>Denne bloggen, i skrivende stund på XmasB er en norsk blogg som jeg har hatt ganske lenge nå. Fotobloggen Captured Echoes er på engelsk, og har vært aktiv i snart et år. Jeg hadde store planer om hvordan den skulle bli, men kom aldri helt i mål. Først og fremst på grunn av misnøye med valg av navn, design og ikke minst mangel på innhold. Det er vanskelig å skylde på noen andre enn seg selv&#8230; <img src='http://xmasb.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Når jeg nå ønsker å flytte bloggene er det først og fremst for å samle bloggene på et sted, samt knytte et navn til både blogg og bilder som er litt mer fornuftig for de fleste sammenhenger. En utfordring jeg ser allerede før jeg har startet selve flyttingen er å flytte innhold uten å få med seg alt av &laquo;søppel&raquo; som har samlet seg opp gjennom årene, først og fremst på denne bloggen, men også på fotobloggen hvor jeg ønsker å endre hele strukturen på hvordan bloggen er bygget opp. Et alternativ er selvsagt å bare skrote alt eksisterende, og begynne på ny. Det kommer ikke til å skje. Jeg ønsker å ta vare på postene, bildene, og kanskje viktigst av alt; alle kommentarer fra fjern og nær.</p>
<p>Jeg har også vurdert å endre språk på denne bloggen, men jeg beholder det nok slik det er i dag. Av flere grunner. En utfordring da er selvsagt at jeg ønsker å ha fotobloggen på engelsk. Det er også denne jeg først og fremst ønsker å endre på, så et alternativ kan være å kun flytte fotobloggen.</p>
<p>Fotobloggen har idag alle filene lagret på egen server. Det er jeg ikke sikker på at jeg ønsker å fortsette med. Jeg betaler tross alt for en Flickr konto jeg ikke bruker, som fint kan brukes til å ha bildene mine på, og ikke minst trekke mer oppmerksomhet til bloggen(e).</p>
<p>Uansett hva jeg ender opp med å gjøre, så blir det forandringer på både design og innhold. Jeg gleder meg!</p>
]]></content:encoded>
			<wfw:commentRss>http://xmasb.com/2009/09/21/jeg-flytter/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Bloglovin? Joda, kan jeg vel.</title>
		<link>http://xmasb.com/2009/07/17/bloglovin-joda-kan-jeg-vel/</link>
		<comments>http://xmasb.com/2009/07/17/bloglovin-joda-kan-jeg-vel/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 12:47:46 +0000</pubDate>
		<dc:creator>Yngve Thoresen</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Blogg]]></category>
		<category><![CDATA[Bloglovin]]></category>

		<guid isPermaLink="false">http://xmasb.com/?p=1151</guid>
		<description><![CDATA[Jeg har notert meg at stadig flere hiver seg på Bloglovin. Så nå har jeg registrert meg, jeg og. Det var til og med noen som hadde lagt til bloggen min allerede, så da trengte jeg bare å kreve bloggen som min. Personlig bruker jeg vel egentlig Google Reader til det meste bloglovin brukes til, [...]]]></description>
			<content:encoded><![CDATA[<p>Jeg har notert meg at stadig flere hiver seg på <a href="http://www.bloglovin.com/no">Bloglovin</a>. Så nå har jeg registrert meg, jeg og. Det var til og med noen som hadde lagt til bloggen min allerede, så da trengte jeg bare å kreve bloggen som min. Personlig bruker jeg vel egentlig Google Reader til det meste bloglovin brukes til, men det er jo greit å &laquo;eie&raquo; de profilene som finnes av meg på nett selv.</p>
<p>Så da har jeg lagt til <a href="http://www.bloglovin.com/no/blog/69969/xmasb">XmasB</a> og <a href="http://www.bloglovin.com/no/blog/858746/captured-echoes">Captured Echoes</a>. God fornøyelse!</p>
]]></content:encoded>
			<wfw:commentRss>http://xmasb.com/2009/07/17/bloglovin-joda-kan-jeg-vel/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

