// Redirecting user to login page if login information is not provided
if (($login == "") || ($passwd == ""))
return header("Location: login.html");
/*
--------------------------------------------------------------------------------
Following part of the script is used to authenticate user on Yahoo!
--------------------------------------------------------------------------------
*/
// Setting URL that is used to authenticate user on Yahoo
$url = "https://login.yahoo.com/config/login?";
// Setting user agent
$useragent = "YahooSeeker-Testing/v3.9 (compatible; Mozilla 4.0; MSIE 5.5; http://search.yahoo.com/)";
// Initiallizing cURL
$ch = curl_init();
/*
Setting cURL options
- User agent
- HTTP Referer
- URL
- Number of input fields to be sent via POST method
- Defining input fields key and value
- value for the input field .done will change depending on the service page you want to visit
- Cookie file to keep session information
- File where output to be saved
- Specifying not to include header in output
*/
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_REFERER, "http://mail.yahoo.com");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 22);
curl_setopt($ch, CURLOPT_POSTFIELDS, "login=$login&passwd=$passwd&.src=&.tries=5&.bypass=&.partner=&.md5=&.hash=&.intl=us&.tries=1&.challenge=ydKtXwwZarNeRMeAufKa56.oJqaO&.u=dmvmk8p231bpr&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=0&.v=0&.chkP=N&.last=&.done=http://messenger.yahoo.com/edit/");
// Setting encrypted filename to store cookie information
$cookieFilename = $login;
$cookieFilename = MD5($cookieFilename);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFilename);
// Setting filename for the output generated by cURL
$verifyFile = "verifyFile." . MD5($cookieFilename) . ".txt";
$fp = fopen($verifyFile, "w");
// Reading the content of the output
$verifyFileContent = file_get_contents($verifyFile);
/*
Checking whether Yahoo could authenticate the user
- If not authenticated
- closes the cURL
- deletes the output file, cookie file
- redirects user to login page
- Continues if authenticated
*/
if (preg_match("/invalid/i", $verifyFileContent))
{
curl_close ($ch);
unlink($verifyFile);
unlink($cookieFilename);
return header("Location: login.html");
}
else
unlink($verifyFile);
curl_error($ch);
curl_close ($ch);
/*
--------------------------------------------------------------------------------
Following part of the script is used to generate output of desired service
- Messenger list in this case
--------------------------------------------------------------------------------
*/
// Setting second URL which provides the messenger list
$url1 = "http://messenger.yahoo.com/edit/";
$useragent1 = "YahooSeeker-Testing/v3.9 (compatible; Mozilla 4.0; MSIE 5.5; http://search.yahoo.com/)";
// Specifying the Cookie file to be used to make sure the user is authenticated
curl_setopt($ch1, CURLOPT_COOKIEFILE, $cookieFilename);
curl_setopt($ch1, CURLOPT_COOKIE, 1);
// Setting the filename to save the output generated by cURL
$filename = "list." . MD5($cookieFilename) . ".txt";
$fp = fopen($filename, "w");
if (!empty($myList))
{
foreach ($myList as $key => $value)
{
foreach ($value as $subKey => $subValue)
{
echo "<tr";
if ($subKey === 0)
{
// Highlighting the row if the $subKey refers to a Contact Group name
echo " bgcolor='#E09487' style='font-weight:bold;'";
}
echo "><td>";
if ($subKey !== 0)
{
// Displaying the online status of the contact
echo "<img src='http://opi.yahoo.com/online?u=$subValue&m=g' border='0'> ";
}
/*
Contact's yahoo ID on your list
- Removing n
- n is shown in the output when the contact's Add Request is Pending
*/
echo str_replace("n", "", $subValue);
echo "</td></tr>";
}
}
}
echo "</table></font>";
/*
This function is used to clean the HTML tags
- It keeps <b> because it seperates each Contact Group
*/
function cleanHTML($list)
{
foreach ($list as $key => $value)
{
$cleanValue = strip_tags($value, "<b>");
$cleanValue = trim($cleanValue);
if ($cleanValue)
$cleanList[] = $cleanValue; // Setting new array without HTML tags (except <b>)
}
return $cleanList;
}
function cleanSource($sourceArr, $turn)
{
foreach ($sourceArr as $key => $value)
{
// Removing unnecessary lines from top of the output
if ($turn == "top")
{
// Stop cleaning at this point
if (preg_match("/friend list for/i", $value))
{
return $sourceArr;
}
else
{
// Unsetting the array index
unset($sourceArr[$key]);
}
}
// Removing unnecessary lines from bottom of the output
else if ($turn == "bottom")
{
// Stop cleaning at this point
if (preg_match("/\/table/i", $value))
{
return $sourceArr;
}
else
{
unset($sourceArr[$key]);
}
}
}
}