domain search through Linux command and PHP

tutorial for PHP, domain search through Linux command and PHP. Searching the domain information through command line. You can search the domain using the Linux command.

domain search through Linux command and PHP

#whois google.com

using the following command you can find the all domain information.

If you want check when domain created then use following command.

#whois google.com | grep “Created | Creation”

If you want to create PHP script for domain search then use following code


$domain_info = exec("whois google.com | grep 'Created |Creation'");

if($domain_info =''){

echo "Domain is not yet registered";

} else {

echo $domain_info = exec("whois google.com");

}

Above script will only work in Linux server.

deleting all one day old files from folder through php

If you want to find the old files from your system or server then you can use the following code. I used the following code for deleting the old files from system.

deleting all one day old files from folder through php


/*****************Get the path to Extension ****************/
$array_path = explode("/",$_SERVER['SCRIPT_FILENAME']);
<div id=":2e">$dynamic_path = "";
for ($i=0;$i
 if($array_path[$i]!="")
$dynamic_path =$dynamic_path."/".$array_path[$i];

// This linux command will delete the one day older from specific folder.
exec("find ".$dynamic_path."* -mtime +1 -exec rm {} \;");</pre>
<div>
For deleting the old files from system I used the Linux command. You can execute the command using the exec function.
If you want to use the Linux command then use the following command
# find /home/user/test/ -m

deleting all one day old files from folder through php
deleting all one day old files from folder through php

time +1 exec rm {}

Above code will only work in Linux server.

how to convert video to flv using php

Tutorial for how to convert video to flv using php. Most of video upload sites are using the ffmpeg and php for uploading and converting the video files.  For converting you need to install the ffmpeg on your server. you can download and install ffmpeg from following location.

how to convert video to flv using php

how to convert video to flv using php
how to convert video to flv using php

http://www.ffmpeg.org/download.html

For installting the ffmpeg on linux box I found following article very helpful

http://mysql-apache-php.com/ffmpeg-install.htm

After installing the ffmpeg on your system you can use following commands for converting the video files to flv format.

avi to flv convert through ffmpeg

ffmpeg -i 00138.avi  -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv final.flv

For creating the thumbnail the from video file you can use the folowing command.

create thubnail from movie file
ffmpeg -y -i moviefile.avi -vframes 1 -ss 00:01:60 -an -vcodec png -f rawvideo -s 110×90 new.png

In PHP you can use the following code easily.


$video_file = '/pathtovideo/test.avi';

$flvfile ='/pathtoflv/test.flv';

$png_path ='/pathtopng/test.png';

exec("ffmpeg -i ".$video_file."  -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv ".$flvfile.");

//for thumbnail

exec("ffmpeg -y -i ".$video_file." -vframes 1 -ss 00:01:60 -an -vcodec png -f rawvideo -s 110x90 ".$png_path.");

Above code with convert the video file to flv format but my suggestion is convertion of video files will take so much bandwidth on server so use cronjob for converting the video files in night time.

deleting one day old files from folder using php

We given php  code for Checking directory and deleting one day old files from folder using php, from folder in windows or linux through php language. For deleting the files from folder in any system (windows or linux). I created the PHP script for deleting the old files from system.

Earlier I created the script for deleting files from folder but that was for only linux. Then I created script which will work independently. Following script will work in mac or windows or linux.

deleting one day old files from folder using php

 /***************** Delete one day old files ****************/
 $dir = "C://Inetpub/vhosts/yourdomain/tmpfiles";

 if (is_dir($dir)) {
 if ($dh = opendir($dir)) {
 while ($file = readdir($dh)) {
 if(!is_dir($dir.$file)) {
 if (filemtime($dir.DIRECTORY_SEPARATOR.$file) <     strtotime('-1 days')) { //if 1 days old, delete
<div id=":1o">echo "Deleting $dir.$file (old)\n";
 unlink($dir.$file);
 }
 }
 }
 } else {
echo "ERROR. Could not open directory: $dir\n";
 }
 } else {
 echo "ERROR. Specified path is not a directory: $dir\n";
 }
 closedir($dh);

// Above script is platform independent.</div>

convert the wma files through php script in linux

When we use the mobile download we always get the wma files as song file. If you want to convert wma files to mp3 file. For that I written the simple PHP sciprt for converting the wma files through php scirpt.

convert the wma files through php script in linux

Use the following scirpt.

<?php
// Script made for convertion of  .wma to .M3 Converter (media conversion) in Linux
//You need the  mplayer and lame installted in your linux OS

set_time_limit(0);
ReadDirs('/var/www/html/songs/wmamp3/');
function ReadDirs($dir){
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." &amp;&amp; $file != ".." &amp;&amp; $file != "Thumb.db") {
$info = pathinfo($file);
if($info['extension']=='wma') {
$mp3_file = str_replace('.wma','',$file);
$cmd = "mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader '".$dir.$file."';lame -m s -V 3 audiodump.wav;mv audiodump.wav.mp3 '".$dir."mp3/".$mp3_file.".mp3';rm -f audiodump.wav";
system($cmd);
}

}
}
closedir($handle);
}
}
?>

Above script will take wma files from folder and convert all files to mp3 files.

convert the wma files through php script in linux
convert the wma files through php script in linux

 

Bluehost : Mailer Error: SMTP Error: Could not connect to SMTP host

I am using the bluehost for my some sites hosting. For sending emails I used the SMTP service which is provided by bluehost.

Bluehost : Mailer Error: SMTP Error: Could not connect to SMTP host

I used the PHPmailer in my website for sending email. When I tried to use the bluehost SMTP I always got the following error message.

Mailer Error: SMTP Error: Could not connect to SMTP host.”

I solved this issue. I created the following function.


<?php
include("class.phpmailer.php");

function mail_new($fun_to,$fun_subject,$fun_body,$fun_header,$fun_from,$fun_cc){
$mail = new PHPMailer();

$mail->IsSMTP();                                      // set mailer to use SMTP
$mail->Host = "mail.eparinay.com";  // specify main and backup server
//$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "support@purabtech.in";  // SMTP username
$mail->Password = "YOURPSSSWORD"; // SMTP password
$mail->Port       = 26;

$mail->From = $fun_from;
$mail->FromName = "eparinay.com";
$mail->AddAddress($fun_to);
$mail->AddReplyTo($fun_from, $fun_from);

if($fun_cc!=""){
$mail->AddAddress($fun_cc);
}
$mail->WordWrap = 50;                                 // set word wrap to 50 characters
//$mail->AddAttachment("/var/tmp/file.tar.gz");         // add attachments
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
$mail->IsHTML(true);                                  // set email format to HTML

$mail->Subject = $fun_subject;
$mail->Body    = $fun_body;
//$mail->AltBody = "This is the body in plain text for non-HTML mail clients";

if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
}
?>

Where you want to use the mail you just need to include the above script and call the “mail_new” function for sending email through bluehost.

Bluehost - Mailer Error- SMTP Error- Could not connect to SMTP host
Bluehost – Mailer Error- SMTP Error- Could not connect to SMTP host

how to add virtual host in wamp server

In this tutorial we shown, how to add virtual host in wamp server on windows machine. You just need to follow our steps to setup virtual host in wamp server.

how to add virtual host in wamp server

Many PHP developers use the wamp server for development. For creating the virtual host just open the httpd.conf file from following location.

how to add virtual host in wamp server
how to add virtual host in wamp server


C:\wamp\bin\apache\Apache2.2.11

Then un-comment the following line


# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Than open the httpd-vhosts.conf file from following location


C:\wamp\bin\apache\Apache2.2.11\conf\extra\

un-comment the following line


NameVirtualHost *:80

then put the following lines in that file



#ServerAdmin webmaster@dummy-host.localhost
DocumentRoot "C:/wamp/www"
ServerName localhost
ServerAlias localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
<!--<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->VirtualHost>


#ServerAdmin webmaster@dummy-host2.localhost
DocumentRoot "C:/wamp/www/wordpress"
ServerName wordpress.purab.com
ErrorLog "logs/wordpress.purab.com-error.log"
CustomLog "logs/wordpress.purab.com.log" common


Then restart the wamp server. Dont forget to update the hosts file from your system

Open the hosts file from following location.


C:\Windows\System32\drivers\etc

put entry like this.

127.0.0.1       localhost    localhost.localdomain    local.purabtech.in

Have fun!

How optimize all tables using php script

Optimizing tables is very necessary for database. That will improve the your website performance.  Optimize command is helpful to manage database files in right manner. This command will optimize the size of file size of database files.

How optimize all tables using  php script

How optimize all tables using  php script
How optimize all tables using php script

If you want to optimize the all tables of database then use following script.


<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
$dbconnect = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$dbconnect) {
 die('Could not connect: ' . mysql_error());
}
echo 'Connected to database successfully';

mysql_select_db('YOUR_DATABASE',$dbconnect);

dbConnect();
$alltables = mysql_query("SHOW TABLES");

while ($table = mysql_fetch_assoc($alltables))
{
 foreach ($table as $db => $tablename)
 {
 mysql_query("OPTIMIZE TABLE '".$tablename."'")
 or die(mysql_error());
 }
}
echo 'All tables optimized successfully';

mysql_close($dbconnect);
?>

The MySQL Optimize Table command will effectively de-fragment a mysql table and is very useful for tables which are frequently updated and/or deleted.

php encode and decode string with key

Many times php developers want to encode there php or important HTML,CSS or Javascript code. In this article I will show you the very simple encoding with using base64_encode method.

php encode and decode string with key

 

php encode and decode string with key
php encode and decode string with key

Here is working example.

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
$str = 'This is an encoded string';
echo base64_encode($str);

echo base64_decode("VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==");
?></pre>
<pre>

you can create your own antilogarithm for encoding. For more information you can check the following URL

http://php.net/manual/en/function.base64-encode.php

How to use mongodb with php

If you want to use the mongodb with php then you need to install pecl libraries. Mongo extension is not bundled with PHP.

The MongoDB server is built to already work with your current web server. The problem is that you’ll need to install drivers for your preferred backend language – PHP, Ruby, Node.js, Perl, whatever.

How to use mongodb with php

How to use mongodb with php
How to use mongodb with php

For installing the Mongo use following URL:
If you dont have pecl installed on your linux machine then use following command.
# yum install php-pecl*
then use following command
# pecl install mongo
Then open the php.ini file. if you are using the linux then use following command.
# vim /etc/php.ini

## Add following lines, end of php.ini file ##
# MongoDB Driver
extension=mongo.so

Restart the apache webserver using following command
# /etc/init.d/httpd restart
If Mongodb server is running then use can test your mongodb database using following code:
Create the mongotest.php file

<!--?php
// connect
$m = new Mongo();
// select a database
$db = $m--->wordpress;
$collection = $db->wordpressapi;
// add an element
$obj = array( "title" => "Sony this Good.\n", "author" => "Wordpressapi.com" );
$collection->insert($obj);
// add another element, with a different "shape"
$obj = array( "title" => "Wordpressapi.com", "online" => true );
$collection->insert($obj);
// find everything in the collection
$cursor = $collection->find();
// iterate through the results
foreach ($cursor as $obj) {
echo $obj["title"] . "\n";
echo $obj["author"] . "\n";
}
// disconnect
$m->close();
?>

If you open this file in browser then you can see the following words in browser:
Sony this Good. WordPressapi.com Sony this Good. WordPressapi.com
If you want to use the mongodb with php then you need to install pecl libraries. Mongo extension is not bundled with PHP.
For installing the Mongo use following URL:
If you dont have pecl installed on your linux machine then use following command.# yum install php-pecl*
then use following command# pecl install mongo
Then open the php.ini file. if you are using the linux then use following command.
# vim /etc/php.ini

## Add following lines, end of php.ini file ### MongoDB Driverextension=mongo.so

Restart the apache webserver using following command
# /etc/init.d/httpd restart
If Mongodb server is running then use can test your mongodb database using following code:
Create the mongotest.php file

<!--?php
// connect$m = new Mongo();
// select a database$db = $m--->wordpress;$collection = $db->wordpressapi;
// add an element$obj = array( "title" => "Sony this Good.\n", "author" => "Wordpressapi.com" );$collection->insert($obj);
// add another element, with a different "shape"$obj = array( "title" => "Wordpressapi.com", "online" => true );$collection->insert($obj);
// find everything in the collection$cursor = $collection->find();
// iterate through the resultsforeach ($cursor as $obj) {    echo $obj["title"] . "\n";     echo $obj["author"] . "\n";}
// disconnect$m->close();
?>

If you open this file in browser then you can see the following words in browser:Sony this Good. WordPressapi.com Sony this Good. WordPressapi.com