Computer And Internet, Personal, Tips & Trick

This articles inspired to share from my experience when I need to created custom sitemap in XML format for some of my website. Basically we will using PHP to generated URL following the sitemap in XML format. Why should in XML format? because mostly a great search engine using sitemap with XML format as their standard.

So we will using PHP script to generated URL (others will follows standard XML format). Example we have site using PHP and MYSQL we will need to query data from MYSQL and then echo it as URL. The problem is because not all website using same structure I can not give you working scripts to generate sitemap as the result may not working for your site.

The good news, because mostly all website using same method (ex, PHP+mysql blabla) we can use same method to generated sitemap. First we need to make sure the first tag should be like this…

On the second line here comes your job to generated your site URL to listed. The last thing just the closing tag. If you meet problems just read the protocols for sitemap XML standard from here. Learn about each tag function and implement it as needed.

Next step, after we have PHP script that works to generated sitemap we need to make it looks like static sitemap. This trick can be done from your .htacess file by rewrite sitemap.php to become sitemap.xml, Just put this line on your .htacess file (if you don’t have it created one).

RewriteEngine on
RewriteRule ^sitemap.xml$ sitemap.php [L]

Done, it will rewrite sitemap.php to become sitemap.xml and looks like static sitemap. Next step, This sitemap will shown as XML in internet explorer but not in mozilla firefox so we need to declare it as XML. Just put this code on the first line..

header(“Content-Type: text/xml; charset=utf-8″)

Next, If you have more than 5,000 URL you can generated it and saved each sitemap and giving parent sitemap.

The result will shown like this sample:

In this sample I’m using PHP function to read folder and files because basically my site using folder and files to generated links. In another sample I’m using mysql query to generated my sitemap.

If yours company need someone to making scripts like this I can do it for $100 – $10,000 deppend on how hard to coding it. That’s my share for today, sorry for not blogging over a month. I promised will write more in the future.

Have a nice day :)

    Digg Del.icio.us StumbleUpon Reddit Twitter RSS
Computer And Internet, Personal, Tips & Trick

In this short tutorial we will learn how to blocking bad referrer site using php script. This idea coming into my head after I’m sick looking at bad referrer site which take opportunity to earn money using my articles. Example: the baddest shortest URL adf.ly, this site shorten URL but it’s reported contain spyware and malware on ads from that page.

This will lead our site in problem because people may think we’re spreading spyware/malware. Even if we claim we don’t created that link I believe 99% people wouldn’t trust us. The best thing to stop this madness is blocking that referrer site to stop referring people into our page.

This php script will using php referrer function to detected referrer site. In this short code sample we may will be needed more manual working. I believe someone can created better one or maybe a nice plugins? you’re ALLOWED to use this script code.

Before I’m going to write the code I just want to tell everyone I already try to blocking bad referrer via .htacces file but it’s not working, I believe there something missing on there… So here is the sample code:

<?php
if ($_SERVER['HTTP_REFERER']){
if ($_SERVER['HTTP_REFERER'] == ‘BAD-SITE-URL-HERE’) {
echo “REFERRER FROM BAD-SITE-URL HAS BEEN BLOCKED”;
exit;
}
}
?>

The problem is when we’re trying to block another bad site we have to edit this code manually. I hope someone would try to make plugins using this code. At least this code works when I try to blocking some referrer from adf.ly it’s SUCCESS!

For wordpress user where to put this code? Open your admin panel and edit your header.php file, put this code in the top of your header code. This sample script will checking, if referrer coming from badsite it will stop loading pages and giving warning message. When it coming directly of safe site like google, yahoo, bing, etc it will work as usual.

That’s my share for today, happy weekend everyone, enjoy your day :)

    Digg Del.icio.us StumbleUpon Reddit Twitter RSS
Computer And Internet, Personal, Tips & Trick

Here come to my attention to share this tips & trick, Story started when there advertiser want to advertise their ad on specific URL on my site, I got confused on how to make it working.  Basically every PHP code I have are global and I need to make ads showing on specific URL only. Thanks to google as my best online teacher I do googling and found some code but there is nothing really works 100%. Finally I do some modification and found out how to do it.

First, we have make PHP function here is the code:

<?php
function curPageURL() {
$pageURL = ‘http’;
if ($_SERVER["HTTPS"] == “on”) {$pageURL .= “s”;}
$pageURL .= “://”;
if ($_SERVER["SERVER_PORT"] != “80″) {
$pageURL .= $_SERVER["SERVER_NAME"].”:”.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>

In case if this code not working try to download the original currpage.txt

Then in your global code you need to specify the URL you want something to shown, Example:

<?php
$d=”http://www.mysite.com/specify/more/deep.html”;
if ($d==curPageURL())
echo “this is the code you want to shown”
?>

More specific you can coding more using else function.

What the benefit to play using this code? In case like adsense I do a little tricky to playing with visitor visions, sometimes I do shown my own ad and sometimes adsense ad, Result is google love it!, people not feel annoyed, my adsense CTR raised UP, YAY! :P

    Digg Del.icio.us StumbleUpon Reddit Twitter RSS
Computer And Internet, Miscellaneous, Tips & Trick

Well, I just have done optimize SEO for one of my website using 4images gallery system it’s on http://www.innovativedesktop.com basically I play with meta title, keywords, and description. And now I’m using URL rewrite. URL look cool and more search engine friendly I believe after a week or month it will indexed in lot of search engine :D

Here is the way for you’re to using URL rewrite on 4images to make it more search engine friendly REMEMBER this will eat CPU resources. (before you doing this I recommended to backup your files first). Any alternative you can learn about URL rewrite yourself to make it works as you want (google is the best teacher).

1. You need to make .htaccess file and put this code on it

RewriteEngine On
RewriteRule ^lightbox\.html$ lightbox.php?%{QUERY_STRING}
RewriteRule ^lightbox\.([0-9]+)\.html$ lightbox.php?page=$1&%{QUERY_STRING}
RewriteRule ^search\.html$ search.php?%{QUERY_STRING}
RewriteRule ^search\.([0-9]+)\.html$ search.php?page=$1&%{QUERY_STRING}
RewriteRule ^postcard([a-zA-Z0-9]+)\.html$ postcards.php?postcard_id=$1&%{QUERY_STRING}
RewriteRule ^postcard\.img([0-9]+)\.html$ postcards.php?image_id=$1&%{QUERY_STRING}
RewriteRule ^k_(.*)_([0-9]+).html categories.php?cat_id=$2&%{QUERY_STRING}
RewriteRule ^r_(.*)_([0-9]+).html details.php?image_id=$2&%{QUERY_STRING}
RewriteRule ^r([0-9]+).search.html details.php?image_id=$1&%{QUERY_STRING}

2. Open /include/sessions.php before the last line add this code

//Mod_bmollet
/**
* Get the category url
* @param int $cat_id The id of the category
* @param string $cat_url The current status of the URL
*/
function get_category_url($cat_id,$cat_url = ”)
{
global $site_db;
$sql = “SELECT cat_name,cat_parent_id FROM “.CATEGORIES_TABLE.” WHERE cat_id = ‘”.$cat_id.”‘”;
$result = $site_db->query($sql);
$row = $site_db->fetch_array($result);
$row['cat_name'] = strtr($row['cat_name'], “éèêàëâúóíáABCDEFGHIJKLMNOPQRSTUVWXYZ”,”eeeaeauoiaabcdefghijklmnopqrstuvwxyz”);
$cat_url = ‘_’.str_replace(‘+’,'_’,urlencode($row['cat_name'])).’_’.$cat_id.$cat_url;
// if you want full path of category in url, put next line in comment
return $cat_url;
if( $row['cat_parent_id'] != 0)
{
return get_category_url($row['cat_parent_id'],$cat_url);
}
else
{
return $cat_url;
}
}
//Mod_bmollet
/**
* Get the image url
* @param int $image_id The id of the image
*/
function get_image_url($image_id)
{
global $site_db;
$sql = “SELECT cat_id,image_name FROM “.IMAGES_TABLE.” WHERE image_id = ‘”.$image_id.”‘”;
$result = $site_db->query($sql);
$row = $site_db->fetch_array($result);
$row['image_name'] = strtr($row['image_name'], “éèêàëâúóíáABCDEFGHIJKLMNOPQRSTUVWXYZ”,”eeeaeauoiaabcdefghijklmnopqrstuvwxyz”);
// if you want comlpete path to image in url, remove comment from following line
//return get_category_url($row['cat_id']).’-’.str_replace(‘+’,'-’,urlencode($row['image_name'])).’-’.$image_id;
return ‘_’.str_replace(‘+’,'_’,urlencode($row['image_name'])).’_’.$image_id;
}
Read More »

    Digg Del.icio.us StumbleUpon Reddit Twitter RSS