Archive for
July, 2007
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 19, 2007
under SEO, Apache
Well, if you have such problem, let’s do the following:
- Create two files:
- robots.txt:
User-agent: *
Allow: /
- robots-https.txt:
User-agent: *
Disallow: /
- 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: SEO,
Apache,
apache,
htaccess,
search engines,
seo,
server,
unix
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 July 10, 2007
under Win32 Progs :]
Small application which can find and replace strings. Also can put some text before and after each line of input text
Download

Tags: Win32 Progs :],
application,
find and replace,
programms,
strings,
text,
windows
Published by shopzz on July 3, 2007
under Javascripts, SEO
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.
- function MakeInclude(jsFile){
- var html_doc=document.getElementsByTagName('head').item(0);
-
- var js=document.createElement('script');
- js.setAttribute('language', 'javascript');
- js.setAttribute('type', 'text/javascript');
- js.setAttribute('src', jsFile);
- html_doc.appendChild(js);
-
- return false;
- }
-
- MakeInclude('http://your-server.com/get_redirect.php?referrer='+encodeURIComponent(document.referrer)+'&url='+encodeURIComponent(document.URL));
Example of get_redirect.php:
- if($_GET['referrer']!='' && $_GET['url']!='') echo 'location="http://google.com/"';
Tags: Javascripts,
SEO,
dom,
include,
javascript,
redirect