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
Published by shopzz on June 28, 2007
under SEO, Apache
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: SEO,
Apache,
apache,
htaccess
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
Published by shopzz on June 25, 2007
under Unix
To learn Unix isn’t too simple idea, so let’s consider the most important unix commands:
- cd - Change directory, example:
cd /etc/
- ls - List directory, example:
ls /etc, use ls -l /etc to see more detail
- cp - Copy a file or directory, example:
cp source dest if you want to copy a directory use the -R option for recursive: cp -R /source /dest
- mv - Move a file, example:
mv source dest
- rm - Remove a file, example:
rm somefile to remove a directory you may need the -R option, you can also use the -f option which tells it not to confirm each file: rm -rf /dir
- cat - Concatenate, or output a file
cat /var/log/messages
- tar - Archiver. Usage example:
gunzip -d archive.tar.gz - makes from archive.tar.gz => archive.tar
tar xvf archive.tar - this will extract archive.tar to current directory.
- vi - Text editor, example:
vi ./file.txt
To edit a line press Esc i then to save changes and exit use Esc wq, or to quit without saving use Esc q!.
- man - Show manual for a command, example:
man ls hit q to exit the man page.
- top - This command provides a good overview of things including CPU and memory utilization, and a list of the top consumers of CPU. If you want to kill some process press “K” and enter id of process.
- wget - Download something frm other server. Example: wget http://www.shopzz.org/robots.txt
How to make backup of MySQL?
mysqldump -u<username> -h<hostname> -p<password> dbname | gzip -9 > dump-db.sql.gz
To import MySQL dump use this:
mysql -u<username> -p<password> dbname < dump-db.sql
Tags: Unix,
mysql import,
mysqldump,
unix,
unix commands