Function to check BOT using php script

Here is the script to check bot crawling:
function is_bot(){
$botlist = array(“Teoma”, “alexa”, “froogle”, “Gigabot”, “inktomi”,
“looksmart”, “URL_Spider_SQL”, “Firefly”, “NationalDirectory”,
“Ask Jeeves”, “TECNOSEEK”, “InfoSeek”, “WebFindBot”, “girafabot”,
“crawler”, “www.galaxy.com”, “Googlebot”, “Scooter”, “Slurp”,
“msnbot”, “appie”, “FAST”, “WebBug”, “Spade”, “ZyBorg”, “rabaz”,
“Baiduspider”, “Feedfetcher-Google”, “TechnoratiSnoop”, “Rankivabot”,
“Mediapartners-Google”, “Sogou web spider”, “WebAlta Crawler”,”TweetmemeBot”,
“Butterfly”,”Twitturls”,”Me.dium”,”Twiceler”);

foreach($botlist as $bot){
if(strpos($_SERVER['HTTP_USER_AGENT'],$bot)!==false)
return true; // Is a bot
}

return false; // Not a bot
}

How to get count of facebook like button and shared links

You might want to get some information on the URL via some automated processes like cronjobs etc. You can simply use FQL – the Facebook Query Language – for that purpose. FQL is similar to SQL but doesn’t support all of the features:
Using FQL
Here is some FQL to get some statistics for a link:
SELECT like_count, total_count, share_count, click_count from link_stat where url=”http://blog.kapilsakhare.in/php/how-to-get-count-of-facebook-like-button-and-shared-links/”
You can simply use a Facebook API client SDK or access the data directly via the URL even in your browser:
https://api.facebook.com/method/fql.query?query=select%20%20like_count,%20total_count,%20share_count,%20click_count%20from%20link_stat%20where%20url=%22http://blog.kapilsakhare.in/php/how-to-get-count-of-facebook-like-button-and-shared-links/%22

This will return XML like this:
<?xml version=”1.0″ encoding=”UTF-8″?>
<fql_query_response xmlns=”http://api.facebook.com/1.0/” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” … Continue Reading

PHP 5.4.0 Release Announcement

Hi Guys,

It’s good news for PHP Developers that PHP 5.4 has been released with exciting new features.
To know more about this, please visit:

http://php.net/releases/5_4_0.php

Some useful ffmpeg commands

Extracting images from a video file using ffmpeg:

Extract single frame at 10th second (ffmpeg uses HH:MM:SS:sss format) of the video:
$ ffmpeg -i input.avi -r 1 -ss 00:00:10.000 -f image2 output_%05d.png
Extract a frame every 2 seconds of the video:
$ ffmepg -i input.avi -r 0.5 -f image2 output_%05d.png
Extract all frames from the input video:
$ ffmpeg -i input.avi -f image2 output_%05d.png
To combine images into a video file (avi container with HuffYUV encoding with 30 fps for this example).
One thing to not here is ffmpeg assumes the input frame rate is 25 by default and does not put all the frames inside the output … Continue Reading

WordPress Track post views without a plugin using post meta

Add this code into the functions.php of your wordpress theme then follow step 1. and step 2. to display the number of views for each post.
PHP – functions.php
function getPostViews($postID){
$count_key = ‘post_views_count’;
$count = get_post_meta($postID, $count_key, true);
if($count==”){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, ’0′);
return “0 View”;
}
return $count.’ Views’;
}
function setPostViews($postID) {
$count_key = ‘post_views_count’;
$count = get_post_meta($postID, … Continue Reading

Parse error: syntax error, unexpected $end

If you have are using the short form (<? ?> ) for PHP instead of the long form (<?php ?>) you might be faced with this parse error when running your script on different systems:
Parse error: syntax error, unexpected $end in X on line Y
where X is the file path and Y the line number, usually the last line of the file.
To avoid this error, refrain yourself from using the short form and stick to (<?php ?>), despite the extra 3 characters. This will make your code universally accessible and it is essential if your developing for beyond your own … Continue Reading

MySql Interview Questions Part-II

How do you start and stop MySQL on Windows? - net start MySQL, net stop MySQL
How do you start MySQL on Linux? - /etc/init.d/mysql start
Explain the difference between mysql and mysqli interfaces in PHP? - mysqli is the object-oriented version of mysql library functions.
What’s the default port for MySQL Server? - 3306
What does tee command do in MySQL? - tee followed by a filename turns on MySQL logging to a specified file. It can be stopped by command notee.
Can you save your connection settings to a conf file? - Yes, and name it ~/.my.conf. You might want to change the permissions on the file to 600, … Continue Reading

CSS Interview Questions and Answers Part-III

Can CSS be used with other than HTML documents?
Yes. CSS can be used with any ny structured document format. e.g. XML, however, the method of linking CSS with other document types has not been decided yet.

Can Style Sheets and HTML stylistic elements be used in the same document?
Yes. Style Sheets will be ignored in browsers without CSS-support and HTML stylistic elements used.

What are pseudo-classes?
Pseudo-classes are fictional element types that do not exist in HTML. In CSS1 there is only one element type which can be classed this way, namely the A element (anchor). By creating three fictional … Continue Reading

MySql Interview Questions Part-I

Q:1 How can we take a backup of a MySQL table and how can we restore it. ?
A:1 To backup:
BACKUP TABLE tbl_name[,tbl_name…] TO ‘/path/to/backup/directory’
RESTORE TABLE tbl_name[,tbl_name…] FROM ‘/path/to/backup/directory’
mysqldump: Dumping Table Structure and DataUtility to dump a database or a collection of database for backup or for transferring the data to another SQL server (not necessarily a MySQL server). The dump will contain SQL statements to create the table and/or populate the table.
-t, –no-create-info
Don’t write table creation information (the CREATE TABLE statement).
-d, –no-data
Don’t write any row information for the table. This is very useful if you just want to get a … Continue Reading

CSS Interview Questions and Answers Part-II

Why do style sheets exist?
SGML (of which HTML is a derivative) was meant to be a device-independent method for conveying a document’s structural and semantic content (its meaning.) It was never meant to convey physical formatting information. HTML has crossed this line and now contains many elements and attributes which specify visual style and formatting information. One of the main reasons for style sheets is to stop the creation of new HTML physical formatting constructs and once again separate style information from document content.

What are the advantages/disadvantages of the various style methods?
External Style Sheets
Advantages

Can control styles for multiple documents … Continue Reading

«« Newer Posts · Older Posts »»