Title, meta description & keywords of a webpage using curl

CURL should be enabled for php. You can check it in php.ini. Here is the php code to fetch title, meta keywords & meta description of a webpage by providing its url.

$url = "http://amandip.net/php-mysql/get-emails-from-inbox-of-email-server";
try{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$html = curl_exec($ch);
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
curl_close($ch);

if(!empty($errmsg)){
exit($errmsg);
}

//parsing begins here:
$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');
$title = $nodes->item(0)->nodeValue;

$metas = $doc->getElementsByTagName('meta');

for ($i = 0; $i < $metas->length; $i++)
{
$meta = $metas->item($i);
if(strtolower($meta->getAttribute('name')) == 'description')
$description = $meta->getAttribute('content');
if(strtolower($meta->getAttribute('name')) == 'keywords')
$keywords = $meta->getAttribute('content');
}
}
catch(Exception $e){
exit($e->getMessage());
}

Prevent right click and text selection on webpage

Hello everyone, today i am going to show you, how prevent the user from right clicking web page or selecting the text on web page and copy it. This can be achieved using little css and a javascript event handler function.
To prevent the right click, simply add following to your body tag of page as given below-

<body oncontextmenu="return false">

To prevent the selection of text on web page, add following in your style sheet-

body {
-webkit-user-select: none;
-moz-user-select: -moz-none;
-ms-user-select: none;
user-select: none;

}

This is tested code in one of my website. It works in all latest browsers approx.
Thanks.

Get emails from inbox of email server

Hello everybody, here i will give you a simple php class to view your inbox emails from your Gmail account-

GetEmails();
class ManageEmails
{
function ManageEmails($emailServer, $emailUsername, $emailPassword)
{
$this->Mailbox=@imap_open($emailServer, $emailUsername, $emailPassword);

if(!$this->Mailbox)
{
echo "Error: Connecting to mail server";
exit;
}
}

function GetTotalEmailCount()
{
if(!$this->Mailbox)
return false;

$headers=imap_headers($this->Mailbox);
return count($headers);
}

function GetEmails()
{
if(!$this->Mailbox)
return false;

/* retrieve emails */
$emails = imap_search($this->Mailbox, 'ALL'); //UNSEEN for unread emails in inbox
rsort($emails); // sort emails in reverse order - newest first
$num = 0;
$this->EmailsArr = array();
foreach($emails as $emailIndex)
{
/* get information specific to this email */
$overview = imap_fetch_overview($this->Mailbox,$emailIndex,0);
$message = imap_fetchbody($this->Mailbox,$emailIndex,2); // message body

$this->EmailsArr[$num]["ReadUnread"] = $overview[0]->seen ? 'read' : 'unread';
$this->EmailsArr[$num]["Subject"] = $overview[0]->subject;
$this->EmailsArr[$num]["From"] = $overview[0]->from;
$this->EmailsArr[$num]["SentDate"] = $overview[0]->date;
// $this->EmailsArr[$num]["Message"] = $message;
$this->EmailsArr[$num]["Attachments"] = $this->GetAttachments($emailIndex, "./afiles/");

$num++;
}
$this->printArray($this->EmailsArr); // you can use this array to display emails however you like
}

function GetAttachments($emailIndex,$path)
{
if(!$this->Mailbox)
return false;

$emailObj = imap_fetchstructure($this->Mailbox,$emailIndex);

$filesStr="";
if($emailObj->parts)
{
foreach($emailObj->parts as $key => $value)
{
$enc=$emailObj->parts[$key]->encoding;
if(isset($emailObj->parts[$key]->ifdparameters) && $emailObj->parts[$key]->ifdparameters == 1)
{
$name=$emailObj->parts[$key]->dparameters[0]->value;
$message = imap_fetchbody($this->Mailbox,$emailIndex,$key+1);
if ($enc == 0)
$message = imap_8bit($message);
if ($enc == 1)
$message = imap_8bit ($message);
if ($enc == 2)
$message = imap_binary ($message);
if ($enc == 3)
$message = imap_base64 ($message);
if ($enc == 4)
$message = quoted_printable_decode($message);
if ($enc == 5)
$message = $message;
$fp=fopen($path.$name,"w");
fwrite($fp,$message);
fclose($fp);
$filesStr=$filesStr.$name.",";
}

if(isset($emailObj->parts[$key]->parts))
{
foreach($emailObj->parts[$key]->parts as $keyb => $valueb)
{
$enc=$emailObj->parts[$key]->parts[$keyb]->encoding;
if($emailObj->parts[$key]->parts[$keyb]->ifdparameters)
{
$name=$emailObj->parts[$key]->parts[$keyb]->dparameters[0]->value;
$partnro = ($key+1).".".($keyb+1);
$message = imap_fetchbody($this->Mailbox,$emailIndex,$partnro);
if ($enc == 0)
$message = imap_8bit($message);
if ($enc == 1)
$message = imap_8bit ($message);
if ($enc == 2)
$message = imap_binary ($message);
if ($enc == 3)
$message = imap_base64 ($message);
if ($enc == 4)
$message = quoted_printable_decode($message);
if ($enc == 5)
$message = $message;
$fp=fopen($path.$name,"w");
fwrite($fp,$message);
fclose($fp);
$filesStr=$filesStr.$name.",";
}
}
}
}
}
$filesStr=substr($filesStr,0,(strlen($filesStr)-1)); //remove extra comma
return $filesStr;
}

function DeleteEmail($emailIndex)
{
if(!$this->Mailbox)
return false;

imap_delete($this->Mailbox,$emailIndex);
}

function CloseMailbox()
{
if(!$this->Mailbox)
return false;

imap_close($this->Mailbox,CL_EXPUNGE);
}

function printArray($arr)
{
echo "<pre>";
print_r($arr);
echo "</pre>";
}
}

Setup for Android Development

Hello everyone if you want to start Android Development on windows then you need following steps to setup an environment for android development-
Install required Eclipse IDE version [Version: 4.1.2]
Download ADT Plugin [Android Development Toolkit]

Open Eclipse IDE, Go to ‘Help’ menu and select option ‘Install New Software’
Click on ‘Add’ button placed after ‘work with’ textbox.
In Name field give ‘ADT Plugin’
Then click ‘Archive’ button and select the ADT Plugin zip file downloaded earlier.
Then click ‘Select all’ button and click on ‘Next ‘ and follow instructions.

OR
Alternately You can use http://dl-ssl.google.com/android/eclipse to download required SDK tools.

Download Android SDK Tools from Android website and install them
After Installation, Run SDK Manager.
In this screen you can download and install all versions of Android Platform and all other custom APIs [like Google API for maps] [Max used version of Android SDK in mobiles is Android 2.3.3 – API 10]

Android Virtual Device
Open AVD manager from Android SDK Tools
Click on new Button on right side of opened dialog
Give a name to virtual device and select a target android version
Next add required values for SD card, snapshot and skin.
Then click on new button in Hardware section of dialog
Select one by one hardware support property to add to virtual device [Support properties that are being used by your app or you are going to test your android app with.]

Increase Decrease Web Page Size based on window size

Hello Everybody, Today i will show simple jquery code to adjust the contents div size according to window size.
Both right and left side bars will remain at their actual size but the width and height of contents will adjust
accordingly. Jquery Code for width handling is given below and you can download full demo by click on Download Demo-

<code>
$(document).ready(function(){
var leftBarWidth = $(‘#leftsidebar’).width();
var rightBarWidth = $(‘#rightsidebar’).width();
$(‘#contents’).width($(window).width()-(leftBarWidth+rightBarWidth));
$(window).resize(function() {

$(‘#contents’).width($(window).width()-(leftBarWidth+rightBarWidth));

});
});
</code>

Create a new domain in Direct Admin

Steps to create a new domain at web server-

  1. Open “Direct Admin” login page in a web browser and enter username & password.
  2. Login and click on “User Level” in right bar under “Access Level”.
  3. It will show all the existing domains hosted on web server in main content area under “Domain”.
  4. Click on Domain Administration Button.
  5. Click on “Add another domain” link located below the icons bar at top.
  6. It will show “Create Domain” form.
  7. Type the domain name in the “domain.com” field. [Do not use CAPS, www, or http:// in your domain name.]
  8. After that click on Logout link at top right corner in contents area.

Upload website from FileZilla

Steps to upload a website to a web server-

  1. Following steps will be according to FileZilla_3.3.2 software. Steps may vary for other ftp softwares.
  2. You can download free FileZilla from http://filezilla-project.org/download.php
  3. Install FileZilla and run it.
  4. Click on “Site Manager” option under “File” menu. (Alternatively you can use “Ctrl+s” to open Site Manager.)
  5. Click on “New Site” button in Site Manager dialog box.
  6. Type domain name “example.com” in “Host” field on the right side panel.
  7. Type “21” in port field.
  8. Select “Normal” from “Logontype” combo list box.
  9. Type ftp username & password in “User” and “password” field.
  10. Now click on “Connect” button near the bottom of site manager dialog box.
  11. It will start connecting to server and will show all files & folders in the root of our server in “Remote Site” box located in middle of window.
  12. Open the location of wordpress website folder in “Local Site” field located at left-middle of window.
  13. Open the domains folder of “Remote Site” box. (Double click on it).
  14. It will show a list of domains hosted on server in the “Remote Site” middle box.
  15. Double click on newly created domain name folder to open it in “Remote Site” middle box.
  16. Double click on “public_html” folder to open it. (It will have a folder(cgi-bin) and some files. Delete “index.html” file only. Remaining files and folder will remain as such.)
  17. Now open the local website folder located in the “Local Site” middle box.
  18. It will show folders and files. Select these all folders & files by “Ctrl + A” or “Shift+click”.
  19. Drag these selected folders & files to the right middle box of “Remote Site” in “public_html” folder.
  20. It will start uploading all the files & folders and will show transfers in the bottom panel “Queued files”.
  21. If any file is shown in failed transfers tab, right click on this file and select “Reset & Requeue selected files” to retransfer it.

Run wordpress site on a web server online

Steps to run a wordpress site online on a web server –

  1. Download wordpress from http://wordpress.org/download/ as a zip file.
  2. Extract all files from zip file and upload all the files & folders to the “public_html” of your domain on hosting server.
  3. Open your domain in a web browser.
  4. It will show “Create a Configuration File” button page.
  5. Click on “Create a Configuration File” button. It will show a wordpress page with some info.
  6. Click on “Let’s Go!” button. It will show database details form.
  7. Type database name in first text field.
  8. Type username and password of database server.
  9. Type “127.0.0.1” or “localhost” in “Database Host” field.
  10. Click on Submit.
  11. It will show a page containing a text area. Select all the text in text area. Copy it and paste in a empty notepad (or any other text editor) file.
  12. Save this file named as “wp-config.php”.
  13. Open FileZilla and transfer this file to root folder ([newdomain.com]/public_html) of your domain. (Refer to Steps to upload a website to web server)
  14. Close FileZilla and go to browser where we have opened new domain previously.
  15. Click on “Run the Install” button. Type “Blog-Title” & “Email” in appropriate fields.
  16. Click on “Install WordPress” Button. Note down admin username and password. Click login button.
  17. You can change password by clicking on “Yes, Take me to my profile page” in red color at top.
  18. It will open profile page, type your new password twice in both password fields.
  19. If you do not want to change it now leave password fields blank.

Install wordpress site on local server like apache

Install a wordpress site on local web server –
1. Download wordpress from http://wordpress.org/download/ as a zip file.
2. Extract all files from zip file and upload all the files & folders to the www/website folder of your web server.
3. Open your website in a web browser (for example – http://localhost/website).
4. It will show “Create a Configuration File” button page.
5. Click on “Create a Configuration File” button. It will show a wordpress page with some info.
6. Click on “Let’s Go!” button. It will show database details form.
7. Type database name in first text field.
8. Type username and password of database server.
9. Type “127.0.0.1” or “localhost” in “Database Host” field.
10. Click on Submit.
11. Click on “Run the Install” button. Type “Blog-Title” & “Email” in appropriate fields.
12. Click on “Install WordPress” Button. Note down admin username and password. Click login button.
13. You can change password by clicking on “Yes, Take me to my profile page” in red color at top.
14. It will open profile page, type your new password twice in both password fields.
15. If you do not want to change it now leave password fields blank.