WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Yahoo! Messenger Friend List
Categories : PHP, CURL, HTML and PHP Click here to Update Your Picture
Ehsan Haque
Date : May 18th 2006
Grade : 4 of 5 (graded 7 times)
Viewed : 31634
File : 4399.zip
Images : No Images for this code example.
Search : More code by Ehsan Haque
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

This example shows how to grab your Yahoo! messenger list using PHP cURL

@Author : Ehsan Haque
@Web : http://ehsan.bdwebwork.com
@Demo : http://resource.bdwebwork.com/yahoo_msgr/
@Critical : Update Information to run on localhost: http://ehsan.bdwebwork.com/blog?a=d&b=26&s=4

login.html
<html>
  <head>
    <title>Get your Yahoo! Address Book</title>
  </head>
 
  <body>
    <font face='verdana' color='#999999'>
          <form action="get_list.php" method="post">
              <table width="40%" border="0" align="center" style="font-family:verdana, arial; font-size:12px; border: 1px solid #dddddd">
                  <tr bgcolor="#889933">
                    <td align="center" colspan="2"><b>Your Yahoo! Messenger List</b></td>
                  </tr>
                    <tr>
                        <td align="right">Yahoo! ID:</td>
                        <td><input name="login" id="username" value="" size="17" type="text"></td>
                    </tr>
                    <tr>
                        <td align="right">Password:</td>
                        <td><input name="passwd" id="passwd" value="" size="17" type="password"></td>
                    </tr>
                  <tr>
                    <td align="center" colspan="2"><input type="submit" value="Get My List Now!!" style="font-family:verdana, arial; font-size:12px; background: #FFFFFF"></td>
                  </tr>
                  <tr bgcolor="#889933">
                    <td align="LEFT" colspan="2" style="font-size:10px;color:#fff">
                    AUTHOR: EHSAN HAQUE
                    <br>
                    WEB: <a href="http://ehsan.bdwebwork.com" target="_blank" style="text-decoration:none;color:#fff">HTTP://EHSAN.BDWEBWORK.COM</a>
                    <br>
                    GENERATING Yahoo! Messenger FRIEND LIST USING PHP cURL
                    </td>
                  </tr>
                </table>   
            </form>
      </font>
    </body>
   
</html>


get_list.php

<?

$login   
= $_POST['login'];
$passwd   = $_POST['passwd'];

// 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");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

// Executing cURL
curl_exec($ch);

fclose($fp);

// 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/)";

$ch1 = curl_init();

curl_setopt($ch1, CURLOPT_USERAGENT, $useragent1);
curl_setopt($ch1, CURLOPT_REFERER, "http://messenger.yahoo.com/");
curl_setopt($ch1, CURLOPT_URL, $url1);
curl_setopt($ch, CURLOPT_POST, 0);

// 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");

curl_setopt($ch1, CURLOPT_FILE, $fp);
curl_setopt($ch1, CURLOPT_HEADER, 0);

curl_exec($ch1);

curl_close ($ch1);

fclose($fp);

// Processing the output generated by cURL
include("process_output.php");

// Delete the cookie file and generated outout file
unlink($cookieFilename);
unlink($filename);

?>


process_output.php

<?php

// Reading the output generated by cURL as an array
$sourceArr          = file($filename);

// Cleaning unnecessary lines from top of the output
$cleanSourceArr     = cleanSource($sourceArr, "top");

// Reversing the output array
$cleanSourceArr     = array_reverse($cleanSourceArr);

// Cleaning the unnecessary lines from the bottom of the output
$cleanSourceArr     = cleanSource($cleanSourceArr, "bottom");

// Setting the array back to its original order
$cleanSourceArr     = array_reverse($cleanSourceArr);

// Removing the texts like [Refresh list], [Send a Message], [Delete]
foreach ($cleanSourceArr as $key => $value)
{
 
$p[0] = "/(\[.[^\]]+)/i";
 
$p[10] = "/\]/";
 
$list[] = preg_replace($p, "", $value);
}

// Removing the HTML tags from the output
$cleanListArr       = cleanHTML($list);

// Seperating array by your messenger's Contact Group
$myListArr          = explode("<b>", $cleanListArr[1]);

foreach (
$myListArr as $key => $value)
{
 
$value = trim($value);
  if (
$value != " ")
  {
   
// Removing 
   
$value          = str_replace(" ", "", $value);
   
   
// Removing </b> tag
   
$value          = str_replace("</b>", "", $value);
   
   
/*
    Creating a child array under each Contact Group array index
    - Each contact is seperated by ·
    */
   
$myList[]       = explode("·", $value);
  } 
}
   
   
// Producing your own output
   
echo "<title>" . str_replace(":", "", strip_tags($cleanListArr[0])) . "</title>";
    echo
"<font face='verdana' size='2' color='#000'>";
    echo
$cleanListArr[0];
    echo
"<table border='1' width='30%' cellpadding='3' cellspacing='2' style='font-size:10px'>";
    echo
"<tr bgcolor='#889933' style='color:#fff;'><td>Friend List</td></tr>";
   
    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]); 
      } 
    }   
  }
}

?>



PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use!
Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP
Text Wrapping
Categories : PHP, HTML and PHP, Strings
Dynamic CSS generation for multiple website colouring schemes.
Categories : PHP, CSS, HTML and PHP
A simple php file uploader
Categories : PHP, Filesystem, HTML and PHP
Automatic generation of HTML code for a table. OO interface. Can define colspan, rowspan, table style, cell style, and data style. Simple, but effective.
Categories : PHP, PHP Classes, HTML, HTML and PHP
Simple class to build tables with style sheets
Categories : HTML and PHP, PHP Classes, PHP
a function that builds an HTML select list from any mysql table.
Categories : PHP, MySQL, HTML and PHP
TreeView - Finally a working tree view function to be used as you want. Simple create the Table using the code provided and you will be able to have a tree view in your project. Download the zip to get the images.
Categories : PHP, HTML and PHP, Navigation
PHP based HTML rabbing Tools
Categories : PHP, HTML and PHP, Tag Extractors, Regexps, Beginner Guides
How to preset a text string in a textarea input field
Categories : HTML, HTML and PHP, PHP, Beginner Guides
Upload images restricted by pixel size (Picture width and Picture Height)
Categories : PHP, HTML and PHP, Graphics
Message of the Day - Random Message (Needs MySQL!)
Categories : Databases, HTML and PHP, PHP, MySQL
Open directory and File download
Categories : PHP, Filesystem, Directories, HTML and PHP
A PHP Calendar.
Categories : PHP, Calendar, HTML and PHP
Dynamic form field
Categories : PHP, HTML and PHP, Form Processing