How to Implement Skype API in PHP to Detect User’s Status

0
Shares
How to Implement Skype API in PHP to Detect User’s Status
Rate this post

Skype is one of the biggest instant messaging and free VoIP service provider which is currently managed by Microsoft. The Skype API provides a mechanism for 3rd party application to control UI functions.

The API has basically two layers – communication and command protocol layer. The communication layer is the set of methods for external application to establish a new connection to Skype client. The command protocol layer on the other hand is a text-based language for applications to communicate with Skype client.

In today’s PHP tutorial, we’ll share the process of implementing Skype API to check any user’s status.

Let’s Get Started

First, we’ve to create access Skype status function in order to detect user’s status.

<?php
function get_skype_status($username, $image = false, $icon = false ){
//creating url
//if you need small icon
if($image && $icon)
{
return "http://mystatus.skype.com/smallicon/".$username;
}
//if you need image
else if($image)
{
return "http://mystatus.skype.com/".$username;
}
//or just text
else
{
$url = "http://mystatus.skype.com/". $username.".xml";
//getting contents
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);

$pattern = '/xml:lang="en">(.*)</';
preg_match($pattern,$data, $match);

return $match[1];
}
} ?>

Now, create a file with Index.php to check the user’s status.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title> Space-O |How to use Skype API to Detect Online Users</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<style type="text/css">

img {border-width: 0}
* {font-family:'Lucida Grande', sans-serif;}
</style>
<style>
#status
{
width: 357px;
height: 28px;
font-size: 15px;
}
</style>
</head>
<body>

<?php
function get_skype_status($username, $image = false, $icon = false ){
//creating url
//if you need small icon
if($image && $icon)
{
return "http://mystatus.skype.com/smallicon/".$username;
}
//if you need image
else if($image)
{
return "http://mystatus.skype.com/".$username;
}
//or just text
else
{
$url = "http://mystatus.skype.com/".$username.".xml";
//getting contents
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);

$pattern = '/xml:lang="en">(.*)</';
preg_match($pattern,$data, $match);

return $match[1];
}
}
$status = "";
if(isset($_POST['status']))
{
$ID = $_POST['status'];
//getting skype status icon
$ico = get_skype_status("$ID", true, true);
$status .= "<p>Skype icon:</p>";
$status .= "<p><img src='".$ico."'/></p>";

//getting skype status image
$image = get_skype_status("$ID", true);
$status .= "<p>Skype image:</p>";
$status .= "<p><img src='".$image."'/></p>";

//getting skype status text
$text = get_skype_status("$ID");
$status .= "<p>Skype status:</p>";
$status .= "<p>$text</p>";
$status = 'Your skype id: '.$ID.' status:<br>'.$status.'<br>';
}

echo $status.'
<form action="index.php" method="post">
<input type="text" name="status" id="status" placeholder="Skype Username" /><input type="submit" value="Get Status" style="padding: 5px;" />
<form>';
?>

</body>
</html>

Once you create your Index.php file, define Curl call.

$url = "http://mystatus.skype.com/".$username.".xml";
//getting contents
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);
$pattern = '/xml:lang="en">(.*)</';
preg_match($pattern,$data, $match);

return $match[1];

And done!

Though, this was just for detecting user’s status, but there are certain functionalities you can implement in your PHP web development project. However, if you’re just starting out, and trying to implement in your business project, consult with experts or hire PHP developer to implement Skype API in your project.

 
0
Shares
 

Would You Like to Develop Your Business Website? We Can Help!