Friday, August 26, 2011

Configuration Directives in httpd.conf for file caching in Centos

The Apache HTTP Server configuration file is /etc/httpd/conf/httpd.conf. The httpd.conf file is well-commented and mostly self-explanatory. The default configuration works for most situations; however, it is a good idea to become familiar some of the more important configuration options.

# 480 weeks

Header set Cache-Control "max-age=290304000, public"


also like this

Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
ExpiresDefault A300

Expires A86400


Expires A2592000





Wednesday, August 24, 2011

MySQL prep

MySQL prep makes user input safe to use in SQL queries. MySQL prep should be used whenever user input is piped directly into the SQL query to prevent SQL Injection.

The code below is written in Perl but the same concepts apply to any language.

The code does the following:
Removes whitespace at the beginning and end of the string.
Replaces backslashes (\) with double backslash (\\).
Replaces single quotes (') with backslashed single quote (\').
Replaces percent signs (%) with backslashed percent signs (\%) to prevent wildcard errors with MySQL.
Removes all charactors that are not alpha-numeric, whitespace, or special charactors.
sub mysqlprep {
local ($string) = @_;
$string =~ s/^\s+//g;
$string =~ s/\s+$//g;
$string =~ s/\\/\\\\/g;
$string =~ s/\'/\\\'/g;
$string =~ s/\%/\\\%/g;
$string =~ s/[^\w\s\~\`\!\@\#\$\%\^\&\*\(\)\+\-\=\[\]\\\{\}\|\;\'\"\:\,\.\/\?\<\>]//g;
return $string;
}

Tuesday, August 9, 2011

Change datetime in Ubuntu

View Time

To view the current date and time, the following command will be enough

date
Set Time

To change time means to set a new time. To set time in Ubuntu (or any Linux), just run the following command

sudo date newdatetimestring

where newdatetimestring has to follow the format nnddhhmmyyyy.ss which is described below

nn is a two digit month, between 01 to 12
dd is a two digit day, between 01 and 31, with the regular rules for days according to month and year applying
hh is two digit hour, using the 24-hour period so it is between 00 and 23
mm is two digit minute, between 00 and 59
yyyy is the year; it can be two digit or four digit: your choice. I prefer to use four digit years whenever I can for better clarity and less confusion
ss is two digit seconds. Notice the period ‘.’ before the ss.

Let’s say you want to set your computer’s new time to December 6, 2007, 22:43:55, then you would use:

sudo date 120622432007.55

Tuesday, August 2, 2011

Creating a MySQL View directly in phpMyAdmin

It's simple really; create, run, and verify the SQL SELECT statement that generates the results of the view you're looking to create, and then use that to create the view.

After executing the query in SQL :

In the very bottom right corner of the result is a link for creating the view!

You will have to supply:

VIEW name
Column names - a comma delimited list of the names to use for each column in the view

Once you're done, click the Go button to create the view!

OR in sqlyog type :

create view as test select * from categories