Archive for the 'PHP' Category

Get url via http-proxy in php+curl

Solution:

  1. function GetData($url, $proxy='', $vars=''){
  2.   $ch=curl_init();
  3.   curl_setopt($ch, CURLOPT_URL, $url);
  4.   curl_setopt($ch, CURLOPT_HEADER, 0);
  5.   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  6.   curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  7.  
  8.   if($vars!=''){
  9.     curl_setopt($ch, CURLOPT_POST, 1);
  10.     curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
  11.   }
  12.  
  13.   if($proxy!='')
  14.     curl_setopt($ch, CURLOPT_PROXY, $proxy);
  15.  
  16.   $str=curl_exec($ch);
  17.   curl_close($ch);
  18.  
  19.   return $str;
  20. }

How to use this:

  1. $url='http://site.com/some-url.php';
  2. $proxy='255.255.255.255:80';
  3.  
  4. // post variables
  5. $vars='var1=1&var2=text';
  6.  
  7. $txt=GetData($url, $proxy, $vars);
  8. echo $txt;

Tags: , , ,

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: , , , , , ,

Curl FTP Wrapper

Hey, I found a pretty-nice curl ftp wrapper :)

Read more »


Tags: , , , ,