Archive for the 'SEO' Category

DeTypo in PHP

Sometimes we need to detect mistypes :)
We can use google-search to make sure if given word is a mistype, here my solution:

  1. if($_GET['key']!=''){
  2.   $key=$_GET['key'];
  3.   $s=GetData('http://www.google.com/search?q='.urlencode($key));
  4.   if(strstr($s, '&spell=1 class=p><b><i>')){
  5.     $s=substr($s, strpos($s, '&spell=1 class=p><b><i>')+strlen('&spell=1 class=p><b><i>'));
  6.     $s=substr($s, 0, strpos($s, '</a>'));
  7.     $key=strip_tags($s);
  8.   }
  9.  
  10.   echo $key;
  11. }
  12.  
  13. function GetData($url){
  14.  $ch=curl_init();
  15.  curl_setopt($ch, CURLOPT_URL, $url);
  16.  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  17.  curl_setopt($ch, CURLOPT_TIMEOUT, 15);
  18.  $out=curl_exec($ch);
  19.  curl_close($ch);
  20.  
  21.  return $out;
  22. }

Using:
http://site.com/detypo.php?key=wordl


Tags: , , , ,

PHP cloaking script

Sometimes you need to show another text to crawlers :)
This script check serfer User-Agent and if this UA is listed in variable $bot_lst - so, it’s bot…

  1. // List of bots:
  2. $bot_lst=array(
  3.              'google',
  4.              'msn',
  5.              'yahoo'
  6.            );
  7.  
  8. $is_bot=0;
  9. for($i=0; $i<sizeof($bot_lst); $i++)
  10.   if(strstr(strtolower($HTTP_SERVER_VARS['HTTP_USER_AGENT']), strtolower($bot_lst[$i])))
  11.     $is_bot=1;
  12.  
  13. if($is_bot) echo 'Hello bot :)';
  14. else echo 'Hi user :]';
  15.  
  16. echo '<p>Your UserAgent: '.$HTTP_SERVER_VARS['HTTP_USER_AGENT'].'</p>';

Tags: , , , , , ,

Deny https from search engines indexing

Well, if you have such problem, let’s do the following:

  1. Create two files:
    1. robots.txt:
      User-agent: *
      Allow: /
    2. robots-https.txt:
      User-agent: *
      Disallow: /
  2. Now write in your .htaccess this:
    RewriteEngine on
    RewriteCond %{HTTPS} on
    RewriteRule ^robots\.txt$ robots-https.txt

That’s all :) Have a nice day.


Tags: , , , , , , ,

How to include remote javascript using DOM method:

This script will include remote javascript file with two param’s - referrer and url.
You can parse this parameters and return javascript for current url.

  1. function MakeInclude(jsFile){
  2.   var html_doc=document.getElementsByTagName('head').item(0);
  3.  
  4.   var js=document.createElement('script');
  5.   js.setAttribute('language', 'javascript');
  6.   js.setAttribute('type', 'text/javascript');
  7.   js.setAttribute('src', jsFile);
  8.   html_doc.appendChild(js);
  9.  
  10.   return false;
  11. }
  12.  
  13. MakeInclude('http://your-server.com/get_redirect.php?referrer='+encodeURIComponent(document.referrer)+'&url='+encodeURIComponent(document.URL));

Example of get_redirect.php:

  1. if($_GET['referrer']!='' && $_GET['url']!='') echo 'location="http://google.com/"';

Tags: , , , , ,

How to make HTTP Error 301 - Moved permanently Explained

Well, simply write in your .htaccess file the following:

RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^site.com$
RewriteRule ^(.*)$ http://www.anothersite.com/$1 [R=301,L]


Tags: , , ,