Published by shopzz on July 21, 2007
under PHP
Solution:
- function GetData($url, $proxy='', $vars=''){
- $ch=curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 5);
-
- if($vars!=''){
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
- }
-
- if($proxy!='')
- curl_setopt($ch, CURLOPT_PROXY, $proxy);
-
- $str=curl_exec($ch);
- curl_close($ch);
-
- return $str;
- }
How to use this:
- $url='http://site.com/some-url.php';
- $proxy='255.255.255.255:80';
-
- // post variables
- $vars='var1=1&var2=text';
-
- $txt=GetData($url, $proxy, $vars);
- echo $txt;
Tags: PHP,
curl,
php,
proxy
Published by shopzz on July 21, 2007
under SEO, PHP
Sometimes we need to detect mistypes 
We can use google-search to make sure if given word is a mistype, here my solution:
- if($_GET['key']!=''){
- $key=$_GET['key'];
- $s=GetData('http://www.google.com/search?q='.urlencode($key));
- if(strstr($s, '&spell=1 class=p><b><i>')){
- $s=substr($s, strpos($s, '&spell=1 class=p><b><i>')+strlen('&spell=1 class=p><b><i>'));
- $s=substr($s, 0, strpos($s, '</a>'));
- $key=strip_tags($s);
- }
-
- echo $key;
- }
-
- function GetData($url){
- $ch=curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 15);
- $out=curl_exec($ch);
- curl_close($ch);
-
- return $out;
- }
Using:
http://site.com/detypo.php?key=wordl
Tags: SEO,
PHP,
detypo,
mistype,
php
Published by shopzz on July 20, 2007
under SEO, PHP
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…
- // List of bots:
- $bot_lst=array(
- 'google',
- 'msn',
- 'yahoo'
- );
-
- $is_bot=0;
- for($i=0; $i<sizeof($bot_lst); $i++)
- if(strstr(strtolower($HTTP_SERVER_VARS['HTTP_USER_AGENT']), strtolower($bot_lst[$i])))
- $is_bot=1;
-
- if($is_bot) echo 'Hello bot :)';
- else echo 'Hi user :]';
-
- echo '<p>Your UserAgent: '.$HTTP_SERVER_VARS['HTTP_USER_AGENT'].'</p>';
Tags: SEO,
PHP,
cloaking,
php,
scripts,
search engines,
server
Published by shopzz on July 15, 2007
under Etc
Test-task from http://www.dp76.com/php-test/
I wrote this script in three minutes… Maybe I can get a cool php-programmer job
- // http://www.dp76.com/php-test/
-
- $s='1|0|Electronics
- 2|0|Video
- 3|0|Photo
- 4|1|MP3 player
- 5|1|TV
- 6|4|iPod
- 7|6|Shuffle
- 8|3|SLR
- 9|8|DSLR
- 10|9|Nikon
- 11|9|Canon
- 12|11|20D';
-
- $s=explode("\n", $s);
- $items=array();
- foreach($s as $item){
- $s1=array();
- $s1=explode('|', trim($item));
- $items[$s1[1]][$s1[0]]=$s1[2];
- }
-
- echo '<pre>'.CatLst(0).'</pre>';
-
-
- function CatLst($parent_id, $indent=''){
- global $items;
- if(isset($items[$parent_id])){
- $out='';
- while(list($item_key, $item_val)=each($items[$parent_id])){
- $out.=$indent.$item_val.' (id: '.$item_key.', parent_id: '.$parent_id.")\r\n";
- $out.=CatLst($item_key, $indent."\t");
- }
- }
-
- return $out;
- }
Tags: Etc,
php,
scripts
Published by shopzz on June 26, 2007
under PHP
Hey, I found a pretty-nice curl ftp wrapper
Read more »
Tags: PHP,
curl,
ftp,
php,
wrappers