htaccess Tips, Tricks and Guide
Jun0
I like .htaccess file, when i need anything that file help me. I collect htaccess tips, tricks and guide list from PerishablePress. I hope you’ll be enjoy.
- Stupid htaccess Tricks
- Better Default Directory Views with HTAccess
- WordPress Feedburner HTAccess Redirect for Default (Non-Permalink) Feed URLs
- Redirecting Subdirectories to the Root Directory via HTAccess
- Redirect All Requests for a Nonexistent File to the Actual File
- Perishable Press HTAccess Spring Cleaning, Part 2
- Perishable Press HTAccess Spring Cleaning, Part 1
- Improve Site Security by Protecting HTAccess Files
- Redirect All (Broken) Links from any Domain via HTAccess
- HTAccess Spring Cleaning 2009
Watermark All Uploaded Images in Wordpress
Jun0
I need a code for watermarked all uploaded images in wordpress. I google it, and i find a solution in WP Glamour. You only add this codes and all of your upload images are watermarked. This very easy solution for watermark your images. Because if you try to add watermark with PhotoShop or another image program, it will be so hard for you.
Firstly create a file with name “watermark.php”, after you will add a rule to .htaccess file.
watermark.php
<?
$src = $_GET['src'];
header('Content-type: image/jpeg');
//this will prevent the watermark from showing up in the thumbnail images
if (eregi("150x150", $src)) {
$watermark = imagecreatefrompng('empty.png');
} else {
$watermark = imagecreatefrompng('watermark.png');
}
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatetruecolor($watermark_width, $watermark_height);
if(eregi('.gif',$src)) {
$image = imagecreatefromgif($src);
}
elseif(eregi('.jpeg',$src)||eregi('.jpg',$src)) {
$image = imagecreatefromjpeg($src);
}
elseif(eregi('.png',$src)) {
$image = imagecreatefrompng($src);
}
else {
exit("Your image is not a gif, jpeg or png image. Sorry.");
}
$size = getimagesize($src);
$dest_x = $size[0] - $watermark_width - 0;
$dest_y = $size[1] - $watermark_height - 0;
imagecolortransparent($watermark,imagecolorat($watermark,0,0));
imagecopyresampled($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $watermark_width, $watermark_height);
imagejpeg($image, "", 95);
imagedestroy($image);
imagedestroy($watermark);
?>
.htaccess file
RewriteRule ^(.*)wp-content/uploads/(.*) $1watermark.php?src=wp-content/uploads/$2
Php 5.2.9 Updated But Mysql Doesnt Work
Jun1
I blogged Php 5.2.9 Upgrade. Some of my user updated with using this entry. But i miss something in these entry. Firstly, i have to say. If you upgrade php version, you have to upgrade mysql and php-mysql.
To Upgrade Mysql and Php-Mysql tool
yum --enablerepo=remi update mysql* yum --enablerepo=remi update php-mysql
And there one more thing, he was php4 and upgrade to 5. Firstly we can not upgrade, we install php newly.
Installing Php
yum --enablerepo=remi install php
When you install on old version, there will be somethings to change. Their extentions directory are different
Old One
extension_dir = /usr/lib/php4
New one (Php 5)
extension_dir = /usr/lib/php/modules
And i restarted services
/etc/init.d/mysqld restart /etc/init.d/httpd restart
I get error in httpd restart
PHP Warning: Module ‘mysql’ already loaded in Unknown on line 0
PHP Warning: Module ‘mysqli’ already loaded in Unknown on line 0
Because mysql is standart module in php5, we dont need load mysql in config file. I change php.ini file (/etc/php.ini) Only i add ; character, it is for comments.
;extension=mysql.so ;extension=mysqli.so
Delete Files in Directory Except Some Files
Jun0
If you need to delete some files in directory, you can automize this. Also you can protect some files on that directory. We are using a little PHP Code for it.
PHP CODE:
<?php
// We write our subdirectories for deleting their content
$directories = array("./", "resim1", "resim2", "resim3", "resim4", "resim5");
for($a=0;$a=<count($directories);$a++)
{
if ($source = opendir($directories[$a]))
{
while (false !== ($file = readdir($source)))
{
if ($file != "." && $file != ".." && substr($file ,-4) == ".jpg" && $file != "index.php")
{
$deleting_file = $directories[$a]."/".$file;
if(unlink($deleting_file))
echo($deleting_file." is deleted..");
else
echo("ERROR: ".$deleting_file." is <b>not</b> deleted..");
}
}
}
else
{
echo("ERROR: Not access with ".$directories[$a]);
}
}
?>
Creating Google Sitemap in PHP
Jun0
We can create dynamic sitemap with using PHP & Mysql. My example code is easy to apply your system.
<?PHP
header('content-type: text/xml');
$mysql_username = "";
$mysql_password = "";
$mysql_database = "";
$dblink = mysql_connect("localhost", "$mysql_username", "$mysql_password");
if (!$dblink) {
die('ERROR: Can not connect database' . mysql_error());
}
@mysql_select_db("$mysql_database") or die ("ERROR: Cannot select database");
echo('<'.'?xml version="1.0" encoding="UTF-8"'.'?'.'>');
echo('<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">');
$contentQ = mysql_query("SELECT * FROM content_table");
while($contentR = mysql_fetch_array($contentQ))
{
$url = $contentR["url"];
$adding_date = date("Y-m-d",strtotime($contentR["adding_date"]));
echo("<url>
<loc>http://www.example.com/".$url."</loc>
<lastmod>".$adding_date."</lastmod>
</url>
");
}
$content2Q = mysql_query("SELECT * FROM content2_table");
while($content2R = mysql_fetch_array($content2Q))
{
$url = $content2R["url"];
$adding_date = date("Y-m-d",strtotime($content2R["adding_date"]));
echo("<url>
<loc>http://www.example.com/".$url."</loc>
<lastmod>".$adding_date."</lastmod>
</url>
");
}
echo("</urlset>");
?>
Google Sitemap Plugins for Wordpress
http://www.dicontas.co.uk/blog/google-sitemap-utw-tag-wordpress-plugin/
http://www.arnebrachhold.de/redir/sitemap-home/
http://www.karailiev.net/karailievs-sitemap/
http://southcoastwebsites.co.uk/wordpress/
Calculate Last Week, Last Month in Mysql
Jun2
We need get datas from last week, last month, yesterday and today. We can do it easily in MySQL.
Getting Current Date
SELECT CURDATE();
Result : 2009-06-04
Getting Last Week Datas
SELECT DATE_ADD('2009-06-04', INTERVAL 7 DAY);
Getting Last Month Datas
SELECT DATE_ADD('2009-06-04', 1 MONTH);
Getting Last Year Datas
SELECT DATE_ADD('2009-06-04', INTERVAL 1 YEAR);
And Php example for this calculations, getting last month orders
mysql_query("SELECT * FROM orders WHERE DATE_SUB(CURDATE(),INTERVAL 1 month) <= order_date"));
For more information of Date and time functions :
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
How to Get CPU Information on Linux
Jun3
cat /proc/cpuinfo
or
less /proc/cpuinfo
Memory Information
cat /proc/meminfo
PHP Version Information
php -v
Apache Version Information
httpd -v
Update PHP to 5.2.9 in CentOS
Jun0
I am using CentOS, i need update Php but yum latest Php version is Php 5.2.6. I solve this problem with download RPM from famillecollet.com.
Full Rpm list is in http://rpms.famillecollet.com
Php Latest Download : http://www.php.net/downloads.php
wget http://rpms.famillecollet.com/el5.i386/remi-release-5-4.el5.remi.noarch.rpm rpm -Uvh remi-release-5-4.el5.remi.noarch.rpm yum --enablerepo=remi update php
Here is the list of Drupal Themes:
