<?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>TechniTip.Net &#187; PHP/MySQL</title>
	<atom:link href="http://technitip.net/category/php_mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://technitip.net</link>
	<description>TechniTip.Net - Useful tips regarding technical stuff for things like Linux, MySQL, Apache, PHP, Linux Server, iPhone and more.</description>
	<lastBuildDate>Fri, 03 Feb 2012 18:31:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<image>
<link>http://technitip.net</link>
<url>http://technitip.net/wp-content/plugins/maxblogpress-favicon/icons/favicon-66.ico</url>
<title>TechniTip.Net</title>
</image>
		<item>
		<title>Howto Beautify Ugly .PHP URL&#8217;s</title>
		<link>http://technitip.net/howto-beautify-ugly-php-urls</link>
		<comments>http://technitip.net/howto-beautify-ugly-php-urls#comments</comments>
		<pubDate>Sat, 17 Jan 2009 13:16:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP/MySQL]]></category>
		<category><![CDATA[beautify]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ugly]]></category>
		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://technitip.net/?p=361</guid>
		<description><![CDATA[You probably know this ugly .PHP links with many parameters like http://technitip.net/test.php?param1=p1&#038;param2=p2&#038;param3=p3 I really don&#8217;t like this look. Doesn&#8217;t the following URL look much better? http://technitip.net/test/p1/p2/p3 I think yes. So here is tutorial how you can beautify your links using Apache and mod_rewrite. The Test Script We assume that mod_rewrite is loaded in your Apache [...]<div style="clear: both;">
<strong>Related posts:</strong><ol>
<li><a href='http://technitip.net/php-accelerator' rel='bookmark' title='PHP Accelerator'>PHP Accelerator</a></li>
<li><a href='http://technitip.net/simple-php-flood-protection-class' rel='bookmark' title='Simple PHP Flood Protection Class'>Simple PHP Flood Protection Class</a></li>
<li><a href='http://technitip.net/domain-redirects' rel='bookmark' title='Domain Redirects'>Domain Redirects</a></li>
</ol></div>]]></description>
			<content:encoded><![CDATA[<p>You probably know this ugly .PHP links with many parameters like<br />
<code></p>
<p>http://technitip.net/test.php?param1=p1&#038;param2=p2&#038;param3=p3</p>
<p></code><br />
I really don&#8217;t like this look. Doesn&#8217;t the following URL look much better?<br />
<code></p>
<p>http://technitip.net/test/p1/p2/p3</p>
<p></code><br />
I think yes. So here is tutorial how you can beautify your links using Apache and mod_rewrite.</p>
<p><strong>The Test Script</strong></p>
<p>We assume that mod_rewrite is loaded in your Apache config and generate a simple PHP script called &#8220;test.php&#8221;:</p>
<pre>&lt;?php
echo "Parameter 1: " . $_REQUEST['param1'] . "&lt;br /&gt;";
echo "Parameter 2: " . $_REQUEST['param2'] . "&lt;br /&gt;";
echo "Parameter 3: " . $_REQUEST['param3'] . "&lt;br /&gt;";
?&gt;</pre>
<p>This script gets the parameters param1, param2, etc. which have been given to the PHP page and prints them out. To check it we put the URL into the browser:</p>
<p>http://technitip.net/test.php?param1=p1&#038;param2=p2&#038;param3=p3</p>
<p>And get the result:</p>
<p>Parameter 1: p1<br />
Parameter 2: p2<br />
Parameter 3: p3</p>
<p><strong>Simple Rewrite</strong></p>
<p>Fine, passing parameters to our PHP script is working but still looking ugly. Now we generate a .htaccess file in the root directory of your web directory:<br />
<code><br />
RewriteEngine On<br />
RewriteBase /<br />
RewriteRule ^(test)/?(.*)$ test.php [L,QSA,NC]<br />
</code><br />
What will happen? test.php will be redirected to test and all parameters will be parsed like before, we can test it:<br />
<code></p>
<p>http://technitip.net/test?param1=p1&#038;param2=p2&#038;param3=p3&#038;param4=p4</p>
<p></code></p>
<p><strong>First Parameter Rewrite</strong></p>
<p>Nice, but not yet what we really want. So we put another line into the .htaccess (before our first RewriteRule, not after! It&#8217;s important):<br />
<code><br />
RewriteRule ^(test)/<strong>([a-z0-9]+)(/[^/]+)?</strong>/?(.*)$ test.php?param1=$2 [L,QSA,NC]<br />
RewriteRule ^(test)/?(.*)$ test.php [L,QSA,NC]<br />
</code></p>
<p>For every parameter we need a new expression /<strong>([a-z0-9]+)(/[^/]+)?</strong>/</p>
<p>This will convert the line /test/p1 into test.php?param1=p1. Note that only the characters a-z und 0-9 are allowed as parameters. For the first parameter $2 is used.</p>
<p><strong>Second Parameter</strong></p>
<p>We repeat this step for every further parameter we need to hand over, $4 is used for the second parameter (not $3!):<br />
<code><br />
RewriteRule ^(test)/([a-z0-9]+)(/[^/]+)?/([a-z0-9]+)(/[^/]+)?/?(.*)$ test.php?param1=$2&amp;param2=$4 [L,QSA,NC]<br />
RewriteRule ^(test)/([a-z0-9]+)(/[^/]+)?/?(.*)$ test.php?param1=$2 [L,QSA,NC]<br />
RewriteRule ^(test)/?(.*)$ test.php [L,QSA,NC]<br />
</code></p>
<p><strong>Three Parameters</strong></p>
<p>Or with 3 parameters. Note: Since the .htaccess is parsed from top to bottom the rewrite rule with the highest number of parameters must be located at the top of the .htaccess. $6 is used for the third parameter!<br />
<code><br />
RewriteRule ^(test)/([a-z0-9]+)(/[^/]+)?/([a-z0-9]+)(/[^/]+)?/([a-z0-9]+)(/[^/]+)?/?(.*)$ test.php?param1=$2&amp;param2=$4&amp;param3=$6 [L,QSA,NC]<br />
RewriteRule ^(test)/([a-z0-9]+)(/[^/]+)?/([a-z0-9]+)(/[^/]+)?/?(.*)$ test.php?param1=$2&amp;param2=$4 [L,QSA,NC]<br />
RewriteRule ^(test)/([a-z0-9]+)(/[^/]+)?/?(.*)$ test.php?param1=$2 [L,QSA,NC]<br />
RewriteRule ^(test)/?(.*)$ test.php [L,QSA,NC]<br />
</code></p>
<p>We test again with 3 parameters:<br />
<code></p>
<p>http://technitip.net/test/p1/p2/p3</p>
<p></code><br />
Parameter 1: p1<br />
Parameter 2: p2<br />
Parameter 3: p3</p>
<p>Looks better, indeed.</p>
<p><strong>Hint</strong></p>
<p>Be sure you have enabled &#8220;Options FollowSymLinks&#8221; or Options &#8220;SymLinksIfOwnerMatch&#8221; in your Apache or virtual host config. Otherwise mod rewrite will not work!</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Ftechnitip.net%2Fhowto-beautify-ugly-php-urls&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><div style="clear: both;"><p><strong>Related posts:</strong><ol>
<li><a href='http://technitip.net/php-accelerator' rel='bookmark' title='PHP Accelerator'>PHP Accelerator</a></li>
<li><a href='http://technitip.net/simple-php-flood-protection-class' rel='bookmark' title='Simple PHP Flood Protection Class'>Simple PHP Flood Protection Class</a></li>
<li><a href='http://technitip.net/domain-redirects' rel='bookmark' title='Domain Redirects'>Domain Redirects</a></li>
</ol></p></div>]]></content:encoded>
			<wfw:commentRss>http://technitip.net/howto-beautify-ugly-php-urls/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Performance Tips</title>
		<link>http://technitip.net/mysql-performance-tips</link>
		<comments>http://technitip.net/mysql-performance-tips#comments</comments>
		<pubDate>Sun, 11 Jan 2009 11:20:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP/MySQL]]></category>
		<category><![CDATA[my.cnf]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tuning]]></category>

		<guid isPermaLink="false">http://technitip.net/?p=336</guid>
		<description><![CDATA[Optimizing a MySQL server is probably not very easy. It depends on your database structure, how many users are accessing your server and so on. Basics But there are a few things which could help to improve your performance. On my configuration I&#8217;ve added skip-name-resolve in my.cnf: [mysqld] skip-name-resolve Now the MySQL server will not [...]<div style="clear: both;">
<strong>Related posts:</strong><ol>
<li><a href='http://technitip.net/mysql-optimize-script' rel='bookmark' title='MySQL Optimize Script'>MySQL Optimize Script</a></li>
<li><a href='http://technitip.net/windows-7-performance-tuning' rel='bookmark' title='Windows 7 Performance Tuning'>Windows 7 Performance Tuning</a></li>
<li><a href='http://technitip.net/simple-mysql-backup-script' rel='bookmark' title='Simple MySql Backup Script'>Simple MySql Backup Script</a></li>
</ol></div>]]></description>
			<content:encoded><![CDATA[<p>Optimizing a MySQL server is probably not very easy. It depends on your database structure, how many users are accessing your server and so on.</p>
<p><strong>Basics</strong></p>
<p>But there are a few things which could help to improve your performance. On my configuration I&#8217;ve added skip-name-resolve in my.cnf:</p>
<pre>[mysqld]
skip-name-resolve</pre>
<p>Now the MySQL server will not do any DNS name resolves. Please note that permissions based on hostnames will no longer work!</p>
<p>For security reasons I would also recommend binding only to the localhost address. Using this the MySQL server is not reachable on the Ethernet interface. In earlier version of MySQL this was usually done with the skip-networking parameter.</p>
<pre>[mysqld]
bind-address    = 127.0.0.1</pre>
<p>And I&#8217;ve added skip-external-locking and skip-locking:</p>
<pre>[mysqld]

skip-external-locking
skip-locking</pre>
<p>This could also improve your performance.</p>
<p><strong>Search Length</strong></p>
<p>For text search queries with a allowed length of 2 characters add this line:</p>
<pre>ft_min_word_len="2"</pre>
<p>Otherwise default minimum length is 3 characters, which means that a search query &#8220;select * like &#8216;%AB%&#8217;&#8221; will never return any data.</p>
<p><strong>Cache Settings</strong></p>
<p>Caching seems to be a very important thing when optimizing your server. My feeling is that the standard configuration of a MySQL server is not really designed for machines with 1 GByte memory or above.</p>
<p>Below is my configuration, with a few cache settings increased.</p>
<pre>[mysqld]
query_cache_limit    =  1M
query_cache_size     = 32M
thread_cache_size    =  8
join_buffer          =  1M
table_cache          = 16M
sort_buffer_size     =  2M
read_buffer_size     =  2M
read_rnd_buffer_size =  2M
tmp_table_size       = 48M
max_allowed_packet   = 16M
thread_stack         = 128K
key_buffer_size      = 32M</pre>
<p>This configuration works on a machine with 1 GByte RAM and several databases running. Basically I recommend to increase the cache size settings. And memory helps almost always.</p>
<p>Applies to MySQL version: 5.0.32</p>




<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Ftechnitip.net%2Fmysql-performance-tips&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><div style="clear: both;"><p><strong>Related posts:</strong><ol>
<li><a href='http://technitip.net/mysql-optimize-script' rel='bookmark' title='MySQL Optimize Script'>MySQL Optimize Script</a></li>
<li><a href='http://technitip.net/windows-7-performance-tuning' rel='bookmark' title='Windows 7 Performance Tuning'>Windows 7 Performance Tuning</a></li>
<li><a href='http://technitip.net/simple-mysql-backup-script' rel='bookmark' title='Simple MySql Backup Script'>Simple MySql Backup Script</a></li>
</ol></p></div>]]></content:encoded>
			<wfw:commentRss>http://technitip.net/mysql-performance-tips/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple PHP Flood Protection Class</title>
		<link>http://technitip.net/simple-php-flood-protection-class</link>
		<comments>http://technitip.net/simple-php-flood-protection-class#comments</comments>
		<pubDate>Fri, 09 Jan 2009 20:00:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP/MySQL]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[floodprotection]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[simple]]></category>

		<guid isPermaLink="false">http://technitip.net/?p=258</guid>
		<description><![CDATA[The problem Running PHP scripts with MySQL queries on a web server may need lots of resources and let get the load of your server high. This is especially the case when you will get kind of attacked by scripts which call your PHP scripts very often in a very short time. The idea Having [...]<div style="clear: both;">
<strong>Related posts:</strong><ol>
<li><a href='http://technitip.net/simple-mysql-backup-script' rel='bookmark' title='Simple MySql Backup Script'>Simple MySql Backup Script</a></li>
<li><a href='http://technitip.net/howto-beautify-ugly-php-urls' rel='bookmark' title='Howto Beautify Ugly .PHP URL&#8217;s'>Howto Beautify Ugly .PHP URL&#8217;s</a></li>
<li><a href='http://technitip.net/php-accelerator' rel='bookmark' title='PHP Accelerator'>PHP Accelerator</a></li>
</ol></div>]]></description>
			<content:encoded><![CDATA[<p><strong>The problem</strong></p>
<p>Running PHP scripts with MySQL queries on a web server may need lots of resources and let get the load of your server high. This is especially the case when you will get kind of attacked by scripts which call your PHP scripts very often in a very short time.</p>
<p><strong>The idea</strong></p>
<p>Having a simple PHP class which can be easily included in every PHP script on your server and helps to avoid getting your CPU load very high caused by too much MySQL requests e.g. from scripts scanning your server.</p>
<p><strong>The solution</strong></p>
<p>Somewhere (I don&#8217;t remember where) I&#8217;ve discovered a simple PHP flood protection class.  I&#8217;ve used this as base for my adjustments which does good work me.</p>
<p><strong>How it works</strong></p>
<p>The class stores the IP address and current time of every request into a database. During the next request the stored IP address and time is check and counted. After a given time and number of requests within this time the script will report a flood violation. Now the  IP address will be blocked for a given time, e.g. 10 minutes. After this time the entry will be deleted from the database to keep the contents of the floodprotection table small.</p>
<p><strong>The implementation</strong></p>
<p>In this example the <a title="ADOdb database abstraction library" href="http://adodb.sourceforge.net/" target="_blank">ADOdb database abstraction library for PHP</a> was used. I personally like this library since it offers a good possibility to analyze e.g. time intensive SQL queries and other nice features.</p>
<p>First of all you need a new table in a database, here we assume you already have a database setup:</p>
<pre>CREATE TABLE `floodprotection` (
  `IP` char(32) NOT NULL default '',
  `TIME` char(20) NOT NULL default '',
  `COUNT` bigint(20) NOT NULL default '0',
  `URL` varchar(255) NOT NULL,
  `LOCK` enum('true','false') NOT NULL default 'false',
  PRIMARY KEY  (`IP`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;</pre>
<p>Ok, now generate a sample PHP script, let&#8217;s say a index.php:</p>
<pre>&lt;?php
include("include/config.php");

echo "Flood or no flood, this is the question.";
?&gt;</pre>
<p>Just a regular PHP script which includes a extra config.php script at the top. Next let&#8217;s have a look at this config.php script which can be included in the same way in every PHP script on your server:</p>
<pre>&lt;?php
/***********************************************************
 config.php - global include script.

 2008 - technitip.net
 ***********************************************************/

$config = array();
$config['BASE_DIR'] = '/path/to/my/webpages';

require_once($config['BASE_DIR'].'/include/adodb/adodb.inc.php');
require_once($config['BASE_DIR'].'/include/floodprotection.php');

$DBTYPE     = 'mysql';
$DBHOST     = 'localhost';
$DBUSER     = 'myuser';
$DBPASSWORD = 'mypassword';
$DBNAME     = 'mydatabase';

// open db connection
$conn = &amp;ADONewConnection($DBTYPE);
$conn-&gt;PConnect($DBHOST, $DBUSER, $DBPASSWORD, $DBNAME);

// get the called page name (full path withour host)
$self = $_SERVER[PHP_SELF];

// define pages which should be ignored
$ignore_pages = array(
  "/ignore.php",
  "/other_ignore.php" );

// ignore flooding for certain pages
if ( !in_array( $self, $ignore_pages ))
{
  // create instantce of flood protection class
  $protect = new flood_protection();

  // check the current requet with remote address
  if($protect-&gt;check_request(getenv('REMOTE_ADDR')))
  {
    // dispay error page in case of flooding and exit
    header("Location: error.html");
    exit;
  }
}
?&gt;</pre>
<p>It opens a database connection and calls the flood protection class. Also here it&#8217;s possible to define PHP pages which should be ignored from the flood detection. If a flood is detected a error page &#8220;error.html&#8221; will be displayed.</p>
<p>And finally the floodprotection.php class. Within this class the repeat values for a valid flood as well as the time can be defined. Also a e-mail can be given to which a detected flood will be reported with some debug information. Important referrers like Google are ignored, they never should be blocked!</p>
<p>Please note that there is absolutely no warranty or support for this script.</p>
<pre>&lt;?php
/***********************************************************
 floodprotection.php - a simple floodprotection class.

 2008 - technitip.net
 ***********************************************************/

class flood_protection
{
  // Number of secounds between a request
  var $secs = 1.5;
  // Number of any URL repeats within $secs to cause flood
  var $flood = 20;
  // Number of same URL repeats within $secs to cause flood
  var $repeat = 10;
  // Number of secounds to keep the user blocked
  var $keep_secs = 600;
  // e-eail address to send debug information
  var $email_to = "mailto@mydomain.com";
  // e-eail adress which appears as from
  var $email_from = "flood@mydomain.com";
  // e-eail subject
  var $email_subj = "Flood";

  // internal variables
  var $url = "";
  var $lock = false;

  // add user ip address to database
  function register_user($ip)
  {
    // insert ip and currnt time into database
    $sql = 'INSERT INTO `floodprotection`
            (`IP`,`TIME`,`COUNT`, `URL`)
            VALUES(\'' . mysql_real_escape_string( $ip ) . '\',
                   \'' . $this-&gt;microtime_float() . '\',
                   0,
                   \'' . $this-&gt;url . '\') ';

    $result = mysql_query($sql);

    if(!$result)
    {
      return false;
    }
    return true;
  }

  // returns exact time
  function microtime_float()
  {
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
  }

  // check to see if the user is flooding
  function check_request($ip)
  {
    $this -&gt; url = mysql_real_escape_string($_SERVER['REQUEST_URI']);

    // find out if the user is in the db or not
    if($this -&gt; user_in_db($ip))
    {
      // if yes check if there flooding
      $return = $this-&gt;user_flooding($ip);
      // update there last request
      $this-&gt;update_user($ip);
      // remove old users
      $this-&gt;remove_old_users();

      // return if there is flooding or not
      return $return;
    }
    else
    {
      // if not add user to db
      $this-&gt;register_user($ip);
      // remove expired users
      $this-&gt;remove_old_users();

      // return false because user is not in db
      return false;
    }
  }

  // checks if user is already in db or not
  function user_in_db($ip)
  {
    // query db to see if user is in db
    $sql = 'SELECT `TIME`,`LOCK`
            FROM `floodprotection`
            WHERE `IP` = \''. mysql_real_escape_string( $ip ) . '\'
            LIMIT 1';

    $result = mysql_query($sql);

    // if more than 0 records are returned user is in db
    if(mysql_num_rows($result) &gt; 0)
    {
      $row=mysql_fetch_assoc($result);
      if ( $row['LOCK'] == "true" )
        $this-&gt;lock = true;

      return true;
    }

    // otherwise return false
    return false;
  }

  function user_flooding($ip)
  {
    // don't check flood protection for important search robots
    if ( (strstr($_SERVER[HTTP_USER_AGET] ,' googlebot' )) ||
         (strstr($_SERVER[HTTP_USER_AGENT], 'Googlebot')) ||
         (strstr($_SERVER[HTTP_USER_AGENT], 'Mediapartners-Google')) ||
         (strstr($_SERVER[HTTP_USER_AGENT], 'eBay Relevance Ad Crawler')) ||
         (strstr($_SERVER[HTTP_USER_AGENT], 'Yahoo! Slurp;' )))
     return false;

    // check if user is already locked
    if ( $this-&gt;lock == true )
      return true;

    // query db to see if there is flooding
    $result = mysql_query('
      SELECT `TIME`,`COUNT`,`URL`,`LOCK`
      FROM `floodprotection`
      WHERE `IP` = \''. mysql_real_escape_string( $ip ) . '\'
      AND `TIME` &gt;= ' . ($this-&gt;microtime_float() - $this-&gt;secs) . '
      LIMIT 1');

    if(mysql_num_rows($result) &gt; 0)
    {
      // if more than 0 records are returned there is flooding
      $row=mysql_fetch_assoc($result);

      $s = "";
      $s = $s . "\n" . "Self:  " . $_SERVER[PHP_SELF];
      $s = $s . "\n" . "Ref:   " . $_SERVER[HTTP_REFERER];
      $s = $s . "\n" . "Query: " . $_SERVER[QUERY_STRING];
      $s = $s . "\n" . "Uri:   " . $this-&gt;url;
      $s = $s . "\n" . "UriDB: " . $row['URL'];
      $s = $s . "\n" . "Agent: " . $_SERVER[HTTP_USER_AGENT];
      $s = $s . "\n" . "IP:    " . getenv('REMOTE_ADDR');
      $s = $s . "\n" . "CPU:   " . exec('uptime');
      $s = $s . "\n" . "COUNT: " . $row['COUNT'] . "/" . $this-&gt;flood;

      // user is already locked
      if ( $row['LOCK'] == "true" )
      {
        mail( $email_to, "Lock", $s, "From: " . $email_from );

        return true;
      }

      // to many requests in a certain time =&gt; flood detected
      if ( $row['COUNT'] &gt; $this-&gt;flood )
      {
        $sql = 'UPDATE `floodprotection`
                SET `LOCK`=\'true\'
                WHERE `IP` = \''. mysql_real_escape_string( $ip ) . '\'';
        mysql_query($sql);

        mail( $email_to, "Flood", $s, "From: " . $email_from );

        return true;
      }
      // to many requests in a certain time =&gt; check for same URL
      else if ( $row['COUNT'] &gt; $this-&gt;repeat )
      {
        // check if same URL has been accessed in a certain time
        if ( !strcmp( $row['URL'], $this-&gt;url))
        {
          $sql = 'UPDATE `floodprotection`
                  SET `LOCK`=\'true\'
                  WHERE `IP` = \''. mysql_real_escape_string( $ip ) . '\'';

          mysql_query($sql);

          mail( $email_to, "Flood Repeat", $s, "From: " . $email_from );

          return true;
        }
        else
          return false;
      }
      else
      {
        return false;
      }
    }
    $sql = 'UPDATE `floodprotection`
            SET `COUNT`=\'0\'
            WHERE `IP` = \''. mysql_real_escape_string( $ip ) . '\'';

    mysql_query($sql);

    // otherwise return false
    return false;
  }

  function update_user($ip)
  {
    $sql = 'UPDATE `floodprotection`
            SET `TIME` = \'' . $this-&gt;microtime_float() . '\',
                `COUNT`=`COUNT`+1,
                `URL`=\'' . $this-&gt;url . '\'
            WHERE `IP` = \''. mysql_real_escape_string( $ip ) . '\'';

    // query db to update the user last request
    $result = mysql_query($sql);
  }

  function remove_old_users()
  {
    // query db to remove all the old users
    mysql_query('
      DELETE FROM `floodprotection`
      WHERE `TIME` &lt;= \'' . ($this-&gt;microtime_float() - $this-&gt;keep_secs) . '\'');
  }
}
?&gt;</pre>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Ftechnitip.net%2Fsimple-php-flood-protection-class&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><div style="clear: both;"><p><strong>Related posts:</strong><ol>
<li><a href='http://technitip.net/simple-mysql-backup-script' rel='bookmark' title='Simple MySql Backup Script'>Simple MySql Backup Script</a></li>
<li><a href='http://technitip.net/howto-beautify-ugly-php-urls' rel='bookmark' title='Howto Beautify Ugly .PHP URL&#8217;s'>Howto Beautify Ugly .PHP URL&#8217;s</a></li>
<li><a href='http://technitip.net/php-accelerator' rel='bookmark' title='PHP Accelerator'>PHP Accelerator</a></li>
</ol></p></div>]]></content:encoded>
			<wfw:commentRss>http://technitip.net/simple-php-flood-protection-class/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP Accelerator</title>
		<link>http://technitip.net/php-accelerator</link>
		<comments>http://technitip.net/php-accelerator#comments</comments>
		<pubDate>Fri, 02 Jan 2009 15:18:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP/MySQL]]></category>
		<category><![CDATA[accelerator]]></category>
		<category><![CDATA[eaccelerator]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://technitip.net/?p=148</guid>
		<description><![CDATA[If you have running a webserver with many PHP pages I recommend to use a PHP accelerator like eaccelerator. Installation is really easy: Download the source Unpack the source and change to the unpacked directory run &#8220;phpize&#8221; run &#8220;./configure&#8221; run &#8220;make&#8221; run &#8220;make install&#8221; run &#8216;&#8221;mkdir /tmp/eaccelerator&#8221; run &#8220;chmod 0777 /tmp/eaccelerator&#8221; edit &#8220;/etc/php5/apache2/php.ini&#8221; (e.g. on [...]<div style="clear: both;">
<strong>Related posts:</strong><ol>
<li><a href='http://technitip.net/simple-php-flood-protection-class' rel='bookmark' title='Simple PHP Flood Protection Class'>Simple PHP Flood Protection Class</a></li>
<li><a href='http://technitip.net/howto-beautify-ugly-php-urls' rel='bookmark' title='Howto Beautify Ugly .PHP URL&#8217;s'>Howto Beautify Ugly .PHP URL&#8217;s</a></li>
<li><a href='http://technitip.net/howto-restart-apache-graceful' rel='bookmark' title='Howto Restart Apache Graceful'>Howto Restart Apache Graceful</a></li>
</ol></div>]]></description>
			<content:encoded><![CDATA[<p>If you have running a webserver with many PHP pages I recommend to use a PHP accelerator like <a title="PHP Accelerator" href="http://eaccelerator.net/" target="_blank">eaccelerator</a>. Installation is really easy:</p>
<ul>
<li>Download the <a title="PHP Accelerator" href="http://eaccelerator.net/" target="_blank">source</a></li>
<li>Unpack the source and change to the unpacked directory</li>
<li>run &#8220;phpize&#8221;</li>
<li>run &#8220;./configure&#8221;</li>
<li>run &#8220;make&#8221;</li>
<li>run &#8220;make install&#8221;</li>
<li>run &#8216;&#8221;mkdir /tmp/eaccelerator&#8221;</li>
<li>run &#8220;chmod 0777 /tmp/eaccelerator&#8221;</li>
<li>edit &#8220;/etc/php5/apache2/php.ini&#8221; (e.g. on Debian Etch)</li>
</ul>
<pre>[eAccelerator]
extension="eaccelerator.so"
eaccelerator.shm_size="128"
eaccelerator.cache_dir="/tmp/eaccelerator/"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"</pre>
<ul>
<li>restart apache &#8220;/etc/init.d/apache2 restart&#8221;</li>
</ul>
<p>In my example the shm_size has been set to 128 MByte because the server hosts serveral domains with PHP pages.</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Ftechnitip.net%2Fphp-accelerator&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><div style="clear: both;"><p><strong>Related posts:</strong><ol>
<li><a href='http://technitip.net/simple-php-flood-protection-class' rel='bookmark' title='Simple PHP Flood Protection Class'>Simple PHP Flood Protection Class</a></li>
<li><a href='http://technitip.net/howto-beautify-ugly-php-urls' rel='bookmark' title='Howto Beautify Ugly .PHP URL&#8217;s'>Howto Beautify Ugly .PHP URL&#8217;s</a></li>
<li><a href='http://technitip.net/howto-restart-apache-graceful' rel='bookmark' title='Howto Restart Apache Graceful'>Howto Restart Apache Graceful</a></li>
</ol></p></div>]]></content:encoded>
			<wfw:commentRss>http://technitip.net/php-accelerator/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Optimize Script</title>
		<link>http://technitip.net/mysql-optimize-script</link>
		<comments>http://technitip.net/mysql-optimize-script#comments</comments>
		<pubDate>Wed, 31 Dec 2008 00:08:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP/MySQL]]></category>
		<category><![CDATA[optimize]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://planlos.org/~harry/php/?p=114</guid>
		<description><![CDATA[A nice small PHP script which simple connects to a given MySQL server and optimizes all databases and included tables. Only the internal table &#8220;information_schema&#8221; is skipped because it will show an error. Working with MySQL version 5.0.32 and PHP version 5.2.0 on Debian Etch. Script is designed to run from command line &#8220;php optimize.php&#8221; [...]<div style="clear: both;">
<strong>Related posts:</strong><ol>
<li><a href='http://technitip.net/simple-mysql-backup-script' rel='bookmark' title='Simple MySql Backup Script'>Simple MySql Backup Script</a></li>
<li><a href='http://technitip.net/mysql-performance-tips' rel='bookmark' title='MySQL Performance Tips'>MySQL Performance Tips</a></li>
<li><a href='http://technitip.net/simple-php-flood-protection-class' rel='bookmark' title='Simple PHP Flood Protection Class'>Simple PHP Flood Protection Class</a></li>
</ol></div>]]></description>
			<content:encoded><![CDATA[<p>A nice small PHP script which simple connects to a given MySQL server and optimizes all databases and included tables. Only the internal table &#8220;information_schema&#8221; is skipped because it will show an error.</p>
<p>Working with MySQL version 5.0.32 and PHP version 5.2.0 on Debian Etch.</p>
<p>Script is designed to run from command line &#8220;php optimize.php&#8221; maybe from a cron job. Be careful: avoid running this script during your server &#8220;rush hour&#8221;, it may slow down your server.</p>
<pre>&lt;?php
/***********************************************************
 optimimze.php - optimizes all databases and tables of the
                 given mysql host.

 2008 - technitip.net
 ***********************************************************/

$mysqlhost = "localhost"; // enter MySQL host
$mysqluser = "user";      // enter MySQL user
$mysqlpwd  = "password";  // enter password

###########################################

$connection = mysql_connect($mysqlhost, $mysqluser, $mysqlpwd);
if (mysql_error())
{
  echo "Could not connect to database server! " . mysql_error() . "\n";
  exit;
}

$db_list = mysql_list_dbs();
$i = 0;
$cnt = mysql_num_rows($db_list);

while ($i &lt; $cnt)
{
  $db = mysql_db_name($db_list, $i);
  ###########################################
  mysql_select_db($db, $connection);
  $result = mysql_list_tables($db);

  while ($row = mysql_fetch_row($result))
  {
    if ( $db == "information_schema" )
      continue;

    echo $db . " : `" . $row[0] . "`";

    $sql = "OPTIMIZE TABLE `".$row[0]."`";
    $erg = mysql_query($sql, $connection) or die(mysql_error());
    $data= mysql_fetch_array($erg, MYSQL_ASSOC);

    if($data)
    {
      echo " - " . $data['Msg_text'] . "\n";
    }
  }
  ###########################################
  $i++;
}

?&gt;</pre>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Ftechnitip.net%2Fmysql-optimize-script&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><div style="clear: both;"><p><strong>Related posts:</strong><ol>
<li><a href='http://technitip.net/simple-mysql-backup-script' rel='bookmark' title='Simple MySql Backup Script'>Simple MySql Backup Script</a></li>
<li><a href='http://technitip.net/mysql-performance-tips' rel='bookmark' title='MySQL Performance Tips'>MySQL Performance Tips</a></li>
<li><a href='http://technitip.net/simple-php-flood-protection-class' rel='bookmark' title='Simple PHP Flood Protection Class'>Simple PHP Flood Protection Class</a></li>
</ol></p></div>]]></content:encoded>
			<wfw:commentRss>http://technitip.net/mysql-optimize-script/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple MySql Backup Script</title>
		<link>http://technitip.net/simple-mysql-backup-script</link>
		<comments>http://technitip.net/simple-mysql-backup-script#comments</comments>
		<pubDate>Tue, 30 Dec 2008 13:44:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP/MySQL]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://planlos.org/~harry/php/?p=92</guid>
		<description><![CDATA[The following example scripts performs a simple backup of all MySQL databases. The resulting .sql file is automatically zipped. Using &#8220;find&#8221; backups older than 3 days are deleted, so you will get complete backups of the last 3 days. This script is intended to be called periodically (e.g. every day) from cron: 2 2       * [...]<div style="clear: both;">
<strong>Related posts:</strong><ol>
<li><a href='http://technitip.net/vmware-esx-backup-script' rel='bookmark' title='VMWare ESX Backup Script'>VMWare ESX Backup Script</a></li>
<li><a href='http://technitip.net/mysql-optimize-script' rel='bookmark' title='MySQL Optimize Script'>MySQL Optimize Script</a></li>
<li><a href='http://technitip.net/running-rsync-and-sudo-over-ssh' rel='bookmark' title='Running Rsync and Sudo over SSH'>Running Rsync and Sudo over SSH</a></li>
</ol></div>]]></description>
			<content:encoded><![CDATA[<p>The following example scripts performs a simple backup of all MySQL databases. The resulting .sql file is automatically zipped. Using &#8220;find&#8221; backups older than 3 days are deleted, so you will get complete backups of the last 3 days.</p>
<p>This script is intended to be called periodically (e.g. every day) from cron:</p>
<pre>2 2       * * *   root /root/scripts/mysql_backup.sh</pre>
<pre>#/bin/sh
now=`date "+%Y-%m-%d"`
user="mysql_user"
password="mysql_password"
path="/home/backup/"

cd $path

mysqldump -u $user -p$password  --all-databases | gzip -c &gt; backup_all_$now.sql.gz

# delete files older than 3 days
find . -name "*.gz" -type f -mtime +3 -exec rm {} ";"</pre>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Ftechnitip.net%2Fsimple-mysql-backup-script&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div><div style="clear: both;"><p><strong>Related posts:</strong><ol>
<li><a href='http://technitip.net/vmware-esx-backup-script' rel='bookmark' title='VMWare ESX Backup Script'>VMWare ESX Backup Script</a></li>
<li><a href='http://technitip.net/mysql-optimize-script' rel='bookmark' title='MySQL Optimize Script'>MySQL Optimize Script</a></li>
<li><a href='http://technitip.net/running-rsync-and-sudo-over-ssh' rel='bookmark' title='Running Rsync and Sudo over SSH'>Running Rsync and Sudo over SSH</a></li>
</ol></p></div>]]></content:encoded>
			<wfw:commentRss>http://technitip.net/simple-mysql-backup-script/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

