<?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>Web Development Blog &#187; database</title>
	<atom:link href="http://www.web-development-blog.com/archives/tag/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.web-development-blog.com</link>
	<description>Web development tutorials, SEO articles and PHP script resources</description>
	<lastBuildDate>Sun, 25 Jul 2010 14:38:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Create custom website backups using CRON</title>
		<link>http://www.web-development-blog.com/archives/create-custom-website-backups-using-cron/</link>
		<comments>http://www.web-development-blog.com/archives/create-custom-website-backups-using-cron/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 13:09:54 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[Reviews]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[webfaction]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=507</guid>
		<description><![CDATA[Several weeks ago I was looking for some alternative hosting for Media Temple and found WebFaction. While searching the net I found a few reviews and all of them are very good. Because their shared hosting package look different from others, I took an account. Why Webfaction? Webfaction is a 100% web hosting provider offering [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p>Several weeks ago I was looking for some alternative hosting for Media Temple and found <a rel="nofollow" href="http://www.webfaction.com/?affiliate=finalwebsites">WebFaction</a>. While searching the net I found a few reviews and all of them are very good. Because their shared hosting package look different from others, I took an account.</p>
<h3>Why Webfaction?</h3>
<p><a rel="nofollow" href="http://www.webfaction.com/?affiliate=finalwebsites">Webfaction</a> is a 100% web hosting provider offering shared hosting plans and managed dedicated servers. Very special is that a shared hosting account has advanced features you didn&#8217;t find by other providers. The most important feature is that you get full SSH access to your Linux user directory and processes like PHP and HTTPD are executed as the same user. Having that kind of user accounts gives you much more possibilities like using a reserved amount of memory for a single process or the ability to setup new stuff in the user directory. I think WebFaction doesn&#8217;t provide a shared hosting account for a beginning webmaster, because their control panel is very basic and is mostly used to create new website, applications, email and database accounts. That will say that other functions like protecting directories or creating CRON jobs must be set via SSH and the command line. They create backups for all your website accounts and all databases. That is for the most users enough, but I like to have real time access to a copy to all my files.</p>
<h3>Creating backups for your websites and applications</h3>
<p>While this tutorial is based on my experience with the hosting account by WebFaction, it should work for most other Linux accounts or servers. All you need is full access to the user&#8217;s home directory. In the past I used the backup function provided by the DirectAdmin control panel for all my hosting. Those backup function (similar to other control-panel types) creates one zipped file from all the user data which is stored on a local or remote location. This type of backup will generate a huge server load if sites becoming bigger. In this tutorial we backup our databases to a local location and we are using <strong>rsync</strong> to backup our websites and databases.<span id="more-507"></span></p>
<h3>Creating backups from your database</h3>
<p>First we need one database user which has at least the rights to select an lock tables.</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">GRANT</span> <span style="color: #990099; font-weight: bold;">SELECT</span><span style="color: #000033;">,</span> <span style="color: #990099; font-weight: bold;">LOCK</span> <span style="color: #990099; font-weight: bold;">TABLES</span> <span style="color: #990099; font-weight: bold;">ON</span> <span style="color: #990099; font-weight: bold;">database</span>.<span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">TO</span> <span style="color: #008000;">'yourdumpuser'</span>@<span style="color: #008000;">'localhost'</span></pre></div></div>

<p>If you like to have a single user with full rights for easier database access, you can use this query as an alternative:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">GRANT</span> <span style="color: #990099; font-weight: bold;">ALL</span> <span style="color: #990099; font-weight: bold;">ON</span> <span style="color: #990099; font-weight: bold;">database</span>.<span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">TO</span> <span style="color: #008000;">'yourdumpuser'</span>@<span style="color: #008000;">'localhost'</span></pre></div></div>

<p>Using the rights for the dump user we&#8217;re able to create database backups from the command line like:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysqldump <span style="color: #660033;">-uyourdumpuser</span> <span style="color: #660033;">-hlocalhost</span> <span style="color: #660033;">-pyourdumppassword</span> database <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #660033;">--best</span> <span style="color: #000000; font-weight: bold;">&gt;</span> yourmysqlbackup.gz</pre></div></div>

<p>This command creates an already gzip compressed database backup file. If you have have many databases you need a lot of commands it would be easier to run a bash script like this one:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">DBUSER</span>=<span style="color: #ff0000;">&quot;yourdumpuser&quot;</span>
<span style="color: #007800;">DBHOST</span>=<span style="color: #ff0000;">&quot;localhost&quot;</span>
<span style="color: #007800;">DBPASS</span>=<span style="color: #ff0000;">&quot;yourdumppassword&quot;</span>
<span style="color: #007800;">BACKUPDIR</span>=<span style="color: #ff0000;">&quot;dbbackup&quot;</span>
<span style="color: #007800;">DBS</span>=<span style="color: #000000; font-weight: bold;">`</span>mysql -u<span style="color: #007800;">$DBUSER</span> -h<span style="color: #007800;">$DBHOST</span> -p<span style="color: #007800;">$DBPASS</span> <span style="color: #660033;">-e</span><span style="color: #ff0000;">&quot;show databases&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">for</span> DATABASE <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$DBS</span>
<span style="color: #000000; font-weight: bold;">do</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$DATABASE</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;Database&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #007800;">FILENAME</span>=<span style="color: #007800;">$DATABASE</span>.gz
mysqldump -u<span style="color: #007800;">$DBUSER</span> -h<span style="color: #007800;">$DBHOST</span> -p<span style="color: #007800;">$DBPASS</span> <span style="color: #007800;">$DATABASE</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #660033;">--best</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$BACKUPDIR</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$FILENAME</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>This small script will read all database names (where the user has access to) and creates files for all of them. Add this code into a file and save it under the name <strong>dbbackup.sh</strong> in your Linux home directory and create also the directory <strong>dbbackup</strong> for the files. The new script need to be executable, use chmod 775 to do that. Test the script with the following command within the directory where the script is located.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>dbbackup.sh</pre></div></div>

<h3>Backup your files using rsync</h3>
<p>Next we need a remote backup location to store our data on a safe place. This can be a second server you own or an external service. Important is that you can access that location via SSH. I&#8217;m using <a rel="nofollow" href="http://www.evbackup.com/">EVBackup</a> from ExaVault. They are not very expensive and they offer a great service. They have also a great <a rel="nofollow" href="http://www.evbackup.com/support-rsync-setup-unix-linux-bsd/">tutorial</a> on how-to configure your account to access their servers using rsync via SSH. </p>
<blockquote><p>If you&#8217;re looking for a backup solution to backup, synchronize and/or share your data, you should try <a rel="nofollow" href="https://spideroak.com/download/referral/46a33949edbafae7ee9610233f3e6464">SpiderOak</a>. They offer great backup solutions for multiple desktop PCs. Just try a free account with 2GB of space.</p></blockquote>
<p>After you setup you SSH connection between you server and your backup server we can start using rsync.</p>
<blockquote><p><strong>Note!</strong> We followed the instructions on from the EVBackup site and created a SSL key to access the remote location without providing a password. It&#8217;s <strong>strongly advised</strong> to do the same, otherwise the next steps will not work for you. You can use the instructions from their website for your own server if you change some parameters and values.</p></blockquote>
<p>The following example will copy all files within the <strong>webapps</strong> directory from your local server to the remote location (directory backup-1):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rsync <span style="color: #660033;">-avz</span> <span style="color: #660033;">--delete</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;ssh -i /home/username/backup/ssh_key&quot;</span> <span style="color: #ff0000;">&quot;/home/username/webapps&quot;</span> someuser<span style="color: #000000; font-weight: bold;">@</span>someuser.exavault.com:backup-<span style="color: #000000;">1</span></pre></div></div>

<p><strong>/home/username/backup/ssh_key</strong> is the location of the ssh key you have created before<br />
<strong>/home/username/webapps </strong>is the directory with files you want to backup<br />
<strong>someuser@someuser.exavault.com:backup-1</strong> is the remote location (in this example an account at exavault.com/EVBackup) where all files are stored</p>
<p>Note the parameter <strong>&#8211;delete</strong> will delete files on remote if the didn&#8217;t exist on the local location and <strong>-i</strong> will create a incremental backup. For additional information about the parameters used with <strong>rsync</strong> run this command via the command line: <code>rsync --help</code>.</p>
<h3>Run backups using CRON</h3>
<p>If you have multiple directories to backup you should group them in one bash script:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
rsync <span style="color: #660033;">-avz</span> <span style="color: #660033;">--delete</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;ssh -i /home/username/backup/ssh_key&quot;</span> <span style="color: #ff0000;">&quot;/home/username/webapps&quot;</span> someuser<span style="color: #000000; font-weight: bold;">@</span>someuser.exavault.com:backup-<span style="color: #000000;">1</span>
rsync <span style="color: #660033;">-avz</span> <span style="color: #660033;">--delete</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;ssh -i /home/username/backup/ssh_key&quot;</span> <span style="color: #ff0000;">&quot;/home/username/dbbackup&quot;</span> someuser<span style="color: #000000; font-weight: bold;">@</span>someuser.exavault.com:backup-<span style="color: #000000;">1</span></pre></div></div>

<p>You can add as many <strong>rsync</strong> commands you need in that script, save it in the user&#8217;s home directory with the name <strong>data-backup.ssh</strong>.</p>
<ul>
<li>We need to run the database backup script to store the current data into the <strong>dbbackup</strong> directory</li>
<li>If this backup is finished we start the rsync backup script ( give the first CRON job enough time)</li>
</ul>
<p>An alternative is to merge both bash scripts, but this is not part of this tutorial. Our entries for the crontab file are (use this command: EDITOR=nano crontab -e)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">0</span> <span style="color: #000000;">10</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>username<span style="color: #000000; font-weight: bold;">/</span>dbbackup.sh
<span style="color: #000000;">0</span> <span style="color: #000000;">11</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>username<span style="color: #000000; font-weight: bold;">/</span>data-backup.sh</pre></div></div>

<p>These CRON jobs will run the first script at 10:00AM and the second at 11:00AM.</p>
<p>That&#8217;s all to backup your websites and databases using rsync and CRON. If you like to try Webfaction use <strong>finalwebsites</strong> as promo code, they offer a 60 days money-back guarantee.<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/create-custom-backups-from-your-website-using-curl/" rel="bookmark" title="July 30, 2008">Create custom backups from your website using cURL</a></li>
<li><a href="http://www.web-development-blog.com/archives/how-to-choose-a-wordpress-hosting-provider/" rel="bookmark" title="January 24, 2010">How-to choose a WordPress Hosting Provider</a></li>
<li><a href="http://www.web-development-blog.com/archives/uploading-files-with-curl/" rel="bookmark" title="September 8, 2006">Uploading files with cURL?</a></li>
</ul>
<p><!-- Similar Posts took 3.446 ms --></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/create-custom-website-backups-using-cron/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Count clicks the right way!</title>
		<link>http://www.web-development-blog.com/archives/count-clicks-the-right-way/</link>
		<comments>http://www.web-development-blog.com/archives/count-clicks-the-right-way/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 21:24:06 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[click fraud]]></category>
		<category><![CDATA[clicks]]></category>
		<category><![CDATA[counter]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[IP address]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=236</guid>
		<description><![CDATA[If you own a link list or directory where the listings are ranked (on some page) on the number of outgoing hits, you&#8217;re possible victim of click fraud. There are not only people clicking their own listings many times, ther eare also click bots (remote scripts) which drive the click count &#8220;into the sky&#8221; in [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p>If you own a link list or directory where the listings are ranked (on some page) on the number of outgoing hits, you&#8217;re possible victim of click fraud. There are not only people clicking their own listings many times, ther eare also click bots (remote scripts) which drive the click count &#8220;into the sky&#8221; in a relative short time.</p>
<p>Click fraud is bad for your sites reputation and is not fair to the listings from other websites. In this PHP code show case we will explain what a webmaster need to do to get his <a href="http://www.finalwebsites.com/snippets.php?id=34">click counter</a> visitor friendly and safe.</p>
<blockquote><p>First of all don&#8217;t worry about if a click doesn&#8217;t get counted!</p></blockquote>
<h3>Objectives and requirements</h3>
<p>We need to use a link which is informative for the visitor, a link like <strong><code>http://www.domain.com/click.php?id=234</code></strong> doesn&#8217;t show the visitor the target link. better would be <strong><code>http://www.domain.com/browse.php?url=www.external-site.com</code></strong></p>
<p>We need to identify our visitor, that a click is not counted twice because the visitor click a link twice or more. We store the IP address from the visitor together with a link ID in a database.</p>
<p>We need to protect us against click bots: Many click bots are very smart, they use many IP addresses from different subnets that they look like real people. Some of them even pre-load the website to get the sites referrer information. Since we store the IP address, the click bot can&#8217;t be very effective for the fraudulent listing. Check your click results frequently and check outstanding results (if a regular listing gets normally 10 clicks a day and on some days there are many hundreds, then some one has tried hack your click system).<span id="more-236"></span></p>
<p>You need two database tables, one for the links and one for the clicks. The first one need only an ID and a column for the URL. The table for the clicks needs a column for the URL id, one for the IP address and one for the timestamp:</p>
<p><code>CREATE TABLE `links` ( `ident` INT NOT NULL, `url` VARCHAR( 100 ) NOT NULL , INDEX ( `ident` ) , UNIQUE ( `url` ) ) ENGINE = MYISAM ;</code></p>
<p><code>CREATE TABLE `clicks` ( `site_id` int(11) NOT NULL, `click_time` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,  `ip_adr` varchar(30) NOT NULL,  KEY `site_id` (`site_id`) ) ENGINE=MyISAM;</code></p>
<p>After we created the database tables we need to enter a few links, use a clean way to insert your links. Don&#8217;t use the protocol in the beginning (if you need this, store protocol in a extra table column)</p>
<p>At the moment some one has clicked the link our redirect script is executed (don&#8217;t forget the PHP tags and the building a database connection):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</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;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.yoursite.com/'</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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">get_magic_quotes_gpc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</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> <span style="color: #990000;">stripslashes</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: #339933;">;</span>
	<span style="color: #000088;">$gURL</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</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: #339933;">;</span>
	<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT ident FROM links WHERE ident = '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$gURL</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</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;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</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: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://'</span><span style="color: #339933;">.</span><span style="color: #000088;">$gURL</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ident'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$IP</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$time_diff</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3600</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">24</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">14</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// count ones in 14 days</span>
		<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT COUNT(*) AS testval FROM clicks WHERE ip_adr = '<span style="color: #009933; font-weight: bold;">%s</span>' AND click_time+<span style="color: #009933; font-weight: bold;">%d</span> &amp;gt; NOW() AND site_id = <span style="color: #009933; font-weight: bold;">%d</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$IP</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time_diff</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$test</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'testval'</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;">$tell</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: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO clicks SET ip_adr = '<span style="color: #009933; font-weight: bold;">%s</span>', site_id = <span style="color: #009933; font-weight: bold;">%d</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$IP</span><span style="color: #339933;">,</span> <span style="color: #000088;">$gURL</span><span style="color: #009900;">&#41;</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>
		<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.yoursite.com/'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span></pre></div></div>

<p>First we test if the variable URL exists and check also if there is a records for that URL. I the record exists, we test if there is a click records for the user with from the collected IP address. I the result is empty we add a new click record to our database. If the link is valid the user get redirected to the URL he already clicked, otherwise the visitor gets back to the site homepage.</p>
<p>There are a lot of free or paid scripts with a bad click counting mechanism. Use this snippet to protect your site for click fraud! In most of the cases you need only to add the click database table and you need to modify the SQL data for the links. That&#8217;s all!<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/limit-the-number-of-downloads-per-client/" rel="bookmark" title="May 5, 2007">Limit the number of downloads per client</a></li>
<li><a href="http://www.web-development-blog.com/archives/more-advanced-features-in-phpmyadmin/" rel="bookmark" title="May 12, 2008">More advanced features in phpMyAdmin</a></li>
<li><a href="http://www.web-development-blog.com/archives/some-nice-google-adsense-updates/" rel="bookmark" title="December 13, 2007">Some nice Google Adsense updates</a></li>
</ul>
<p><!-- Similar Posts took 3.789 ms --></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/count-clicks-the-right-way/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Database Management with phpMyAdmin</title>
		<link>http://www.web-development-blog.com/archives/database-management-with-phpmyadmin/</link>
		<comments>http://www.web-development-blog.com/archives/database-management-with-phpmyadmin/#comments</comments>
		<pubDate>Mon, 12 May 2008 13:41:37 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[book review]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpmyadmin]]></category>
		<category><![CDATA[pma]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/archives/database-management-with-phpmyadmin/</guid>
		<description><![CDATA[This is part one of the quick review of the book &#8220;Mastering phpMyAdmin for Effective MySQL Management&#8221; and the phpMyAdmin software. This article/review is not just another review about phpMyAdmin, but more some information about features I haven&#8217;t used during the last years of PHP/MySQL web development. About phpMyAdmin PMA is a full featured tool [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p>This is part one of the quick review of the book &#8220;<a rel="nofollow" href="http://www.packtpub.com/phpmyadmin-3rd-edition/book/mid/300908y6v6we">Mastering phpMyAdmin for Effective MySQL Management&#8221;</a> and the phpMyAdmin software.</p>
<blockquote><p>This article/review is not just another review about phpMyAdmin, but more some information about features I haven&#8217;t used  during the last years of PHP/MySQL web development.</p></blockquote>
<h3>About phpMyAdmin</h3>
<p>PMA is a full featured tool to administrate your MySQL database server via a web browser. While the functions are almost unlimited, it&#8217;s also a powerful tool to maintain the database content even for less experienced users.</p>
<p><img style="float: left; margin-right: 5px" src="http://www.web-development-blog.com/wp-content/uploads/2008/05/5113g6ddtjl_sl110_.jpg" alt="Mastering phpMyAdmin" />It&#8217;s already a year ago (or more) that I got the book &#8220;<a rel="nofollow" href="http://www.packtpub.com/phpmyadmin-3rd-edition/book/mid/300908y6v6we">Mastering phpMyAdmin&#8221;</a> as a present/reward for contributing some snippets on weberdev.com. Finally I found the time to read (most of) the book during a vacation. The book is great for webmasters using phpMyAdmin (PMA) the first time and also more advanced users. The book covers the installation, basic database interactions using PMA like simple INSERT or SELECT commands and also advanced features like the relational system provided by the <a href="http://www.phpmyadmin.net/">phpMyAdmin software</a>.<span id="more-136"></span></p>
<p>More advanced user should read the book to learn more about:</p>
<ul>
<li> Changing the configuration fies to customize your current installation</li>
<li> how to handle binary data inside phpMyAdmin</li>
<li> saving export files on the server</li>
<li> better understanding on how-to import CSV files</li>
<li> complete database search</li>
<li> the PMA relational system</li>
<li> using the Mimer SQL validator</li>
<li> better understanding of the multi table query generator</li>
<li> using bookmarks for frequent used queries</li>
<li> building relational schema in PDF</li>
<li> mime based transformations</li>
<li> character sets and collations</li>
</ul>
<p>While the book is published in 2004 (I see it was time for me to read), the descriptions and screen-shot are actual enough to translate the book information into the users work with the current version of phpMyAdmin.</p>
<h3>The Installation part</h3>
<p>I remember me my first installation of phpMyAdmin, the hardest part was to enter some configuration of paths and database connection parameters. The book shows clear information about<br />
basic installation (one user with one database)</p>
<ul>
<li> Multi server installation</li>
<li> Multiuser installation</li>
<li> restricting access to phpMyAdmin by IP and/or user</li>
</ul>
<p>Sure over the years an experienced user will discover all types of installations, but using this book the user gets a better understanding of features like authentication types or Multi use/server configuration. I must say that the user restriction function in PMA are new to me, sure I didn&#8217;t needed them before. Restrict the access by IP address to allow access only in your companies network, this way a .htaccess user protection is more safe because you are able to control the access from outside of your network!</p>
<h3>The Interface and basic database interactions</h3>
<p>The PMA interface is very self-describing, I found a nice feature for people working with multiple databases accessed by the same user. The nested display  will show tables for each database without selecting a different database.<br />
Do you know the vertical mode for editing multiple records? with setting the configuration value <strong>$cfg['DefaultPropDisplay']</strong> to &#8220;vertical&#8221; the records are arranged in vertical order. A great feature if you edit 2-3 records the same time.<br />
While contributing to <a href="http://www.finalwebsites.com/forums/">PHP forums</a> I noticed often question about database fields from the &#8220;Blob&#8221; type. Sure it&#8217;s not a really good idea to store binary data inside a database, this book will give some useful guidance to store and read this type of content.</p>
<h3>Import and export of data</h3>
<p>Exporting content or complete database tables is a very common function in PMA, but do you noticed the export function even for results based on queries? I got this question very often: &#8220;could you send me just these data from that table?&#8221;, most of the time they got the whole table because it was much faster to export, Or better why not exporting single records from a complete result set?<br />
Another useful feature is to export to the server, this function is available if you configure the safe_dir in your PMA configuration.</p>
<p>For all users on shared hosting platforms is this following feature very useful: By default the upload size and memory limit are very limited. Uploading data import files bigger than 2MB (compressed) could be a problem. The option &#8220;upload_dir&#8221; will help. Create one central folder and upload your import files via FTP, after then select the file from the select box on the import screen.</p>
<h3>Searching and selecting data</h3>
<p>Do you ever noticed the feature &#8220;database search&#8221;? Just access the search tab (without selecting a database table) and search for data using wild cards, an exact phrase or regular expressions get results from your whole database.</p>
<p>This was part one of the PMA / book review, if you like to read more about the <em>relational system, bookmarks and MIME-based transformations</em> subscribe to this  blog post.<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/more-advanced-features-in-phpmyadmin/" rel="bookmark" title="May 12, 2008">More advanced features in phpMyAdmin</a></li>
<li><a href="http://www.web-development-blog.com/archives/save-bandwidth-with-phproxy-and-ip2nation/" rel="bookmark" title="May 30, 2007">Save bandwidth with PHProxy and ip2nation</a></li>
<li><a href="http://www.web-development-blog.com/archives/create-custom-website-backups-using-cron/" rel="bookmark" title="October 17, 2009">Create custom website backups using CRON</a></li>
</ul>
<p><!-- Similar Posts took 5.132 ms --></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/database-management-with-phpmyadmin/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->