Chris Nizzardini, Salt Lake City Utah, Web Developer Specializing in LAMP+Ajax Since 2006

My Blog

Here is my awesome blog.

Archive for June, 2007

linux debian apache2 installing mod-write

Posted by chris on June 23rd, 2007 Comments(0)

To install mod-rewrite in debian type a2enmod rewrite from the shell. You will the be asked to restart apache.

A simple mod-write script that blocks anyone from hotlinking to your images would look like this:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpe [L]

You would either place this in an .htaccess file or if you have root access to the server in /etc/apache2/sites-available and then within the directory you want to protect from hotlinking.

In linux ()

php switch/case statements

Posted by chris on June 18th, 2007 Comments(0)
switch ($i)
{
case 0:
    echo "i equals 0";
    break;
case 1:
    echo "i equals 1";
    break;
case 2:
    echo "i equals 2";
    break;
}

Update: I have a few developers at my work that have a java background and they didn’t know that you can actually include a conditional in your case, cause I guess java doesn’t let you. So for case 1 (in this instance) you could actually have it test against a variable outside the switch so it would read:

$var = 2;
switch ($i)
{
case 0:
    echo "i equals 0";
    break;
case $i == $var:
    echo "i equals 1";
    break;
case $i== $var:
    echo "i equals 2";
    break;
}

I forget where I used this code recently, but it is useful, as it makes your switch more dynamic.

In php ()

linux random tar stuff

Posted by chris on June 15th, 2007 Comments(0)

This will probably grow as I need tar to do more stuff.

Excluding a directory from your tarball:
tar -cf backup.tar /home –exclude “/home/cpanel”

In linux ()

linux search from shell (grep)

Posted by chris on June 4th, 2007 Comment(1)

find . -name ‘*.*’ | xargs grep -l ’search term’

UPDATE
The gentlemen who replied below is correct in stating that the command below would be easier.

grep -ril 'search_term' *
In linux ()

resize images from linux command line w/ imagemagick

Posted by chris on June 3rd, 2007 Comments(0)

In debian execute this shell command apt-get install imagemagick

Now to resize images execute convert -size 125×125 /path/to/image.jpg -resize 125×125 /path/to/image.jpg

Ofcourse you can do this in php by executing the shell command using the exec() function.

In linux, php ()

a backup system – for the poor and lazy

Posted by chris on June 2nd, 2007 Comments(0)

Well I’ve put enough time and effort into my server configuration, mysql databases, and my web dev files that it was finally time to start backing up. Now I’m not completely crazy, the server does have a 3ware card in it for mirroring, but in the end its still a server in the closet (its not gay) and something bad could happen. So I spent about 2 hours writing a few backup scripts because I’m too poor for rsync and too lazy for amanda.

All you need is a cheap web host like the one I use (about $5 a month) and some time. Here’s what I did:

Read the rest of this entry »

In linux, php ()