Thursday, December 9, 2010

PHP Fatal error: Uncaught CurlException: 6: name lookup timed out thrown in Facebook

If you are facebook developer, and are using the latest facebook php sdk, facebook.php grabbed from github.com, and are facing the problem similiar to as defined below:

PHP Fatal error: Uncaught CurlException: 6: name lookup timed out thrown in //facebook.php on line 592

This is probably the host is not given enough time to contact with facebook server. To solve this problem, open facebook.php with your editor, and go to line 89 to find the code below:

1
2
3
4
5
6
public static $CURL_OPTS = array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'facebook-php-2.0',
);

Modify CURLOPT_CONNECTION to increase its value to, 30 or higher.

1
CURLOPT_CONNECTTIMEOUT => 30,

and test your facebook application again to see if it works.

Suggestion: Change to a better host to resolve the problem without modifying the facebook.php script

Saturday, May 22, 2010

Quickbooks Import QBI

http://addons.oscommerce.com/info/2847

Friday, April 23, 2010

Effort Estimation 1






Project Name - Effort Estimation Ver1.0






Proposed Technology : PHP, MYSQL, Javascript, HTML, CSS

Tools: , Dreamweaver, Edit Plus


No. Of Hours
Description Designing Coding
Designing

Logo Designing (2 Samples) 16.00
Creating template for the website 8.00 0.00
Converting template to HTML 10.00 0.00
Integrating template into all the pages of CMS 16.00 24.00
Integrating User pages of CMS 16.00
Integrating admin template into all the pages of CMS 16.00



Database

Database Design 0.00 32.00



Main Site

Displaying Home, About US, Site Map, Terms of use and Services Pages
with content from CMS
12.00 16.00
Contact US Form 4.00
Registration form 8.00
Login Functionality 2.00
Forget password
2.00



Member Section

Update Profile 16.00 4.00



Payment Gateway Section

PayPal Payment Gateway Section
35.00



Admin panel

Manage User (Add/Edit/Delete) 16.00 16.00
Payment Details settings 8.00
CMS for web pages (Home, About US, Site Map, Terms of use and Services Pages) - Main Site 12.00
Change Password Functionality 5.00

78.00 200.00



Others

Testing/QA 69.50
Setting up Sub domain - Test Server Hosting 8.00
Implementation 16.00
Total Number Of Hours (Coding + Design) 371.50



Assumption/ Questions Reply

? Yes / No

? Yes / No

? Yes / No

? Yes / No

? Yes / No



Checklist for TESTERS

1. Get the scope of the project/tasks & urls before starting the testing
Yes /No/Not Applicable

2. Analyze scope document and prepare a list of all tasks/functionalities that are need to be tested
Yes /No/Not Applicable

3.Check those tasks/functionalities are done and they are fully functional
Yes /No/Not Applicable

4.Check the tasks/functionalities in IE 6/ IE 7 /Firefox 2 & 3.

IE 6 -- Yes /No/Not Applicable
IE7 -- Yes /No/Not Applicable
Firefox 2 -- Yes /No/Not Applicable
Firefox 3 -- Yes /No/Not Applicable

5. If the task/functionality requires browser compatibility for any browser (other than the browsers mentioned above), make sure testing has been done on those browsers also.
In your approval mail, mention these browser names also.
Yes /No/Not Applicable

6. If there is any form is involved in the website, check whether that Mandatory fields are listed (or) * is present near the labels and if it’s not mentioned, this should be registered as a bug and this needs to get fixed.
Yes /No/Not Applicable

7. Check whether any javascript error is there in any of the pages. If so and it’s part of the scope, this needs to be corrected. For e.g., You can check this by viewing status bar in the IE Browser and in firefox, you can see this by Tools->Error Console or Javascript console.
Yes /No/Not Applicable


8. Check whether any design related issues are there in the web pages and if so record the same as bugs in the below mentioned browsers and mention the relevant details near by the browser name.

IE 6 -- Yes /No/Not Applicable
IE7 -- Yes /No/Not Applicable
Firefox 2 -- Yes /No/Not Applicable
Firefox 3 -- Yes /No/Not Applicable


9. If the design related issue needs to be checked for browser compatibility for any browser (other than the browsers mentioned above), make sure testing has been done on those browsers also.
In your approval mail, mention these browser names also.
Yes /No/Not Applicable
For e.g., mention like this. Safari - Yes

10. If any mail checking functionality needs to be checked, make sure you have received the emails without any formatting/spelling issues and has proper/relevant subject and proper body content and proper “from address” and also mention which email provider you have checked.
Yes /No/Not Applicable

For e.g.,
Gmail – Yes
Yahoo Mail – No. Formatting is not correct and needs to be corrected.

11. Javascript alert messages are relevant and meaning full and don’t have spelling mistakes and grammar mistakes.
Yes /No/Not Applicable

12. Server side error messages are relevant and meaning full and don’t have spelling mistakes and grammar mistakes.
Yes /No/Not Applicable

13. In Signup/Registration pages, username has been checked for uniqueness and if username already exists, proper message is displayed and user has been shown the same form with fields filled with the values entered by the user.
Yes /No/Not Applicable

14. There is no spelling or grammar mistake in any pages of the website.
Yes /No/Not Applicable

15. When “Delete” option has been clicked in the website page (in general admin or user modules, where records are shown as a list), it asks user confirmation “Yes” or “No” and if we click “Yes” then only selected records have been deleted and proper message has been displayed after successful deletion.
Yes /No/Not Applicable

16. Content in all of the web pages are visible and readable
Yes /No/Not Applicable

17. There is no broken link found in the website
Yes /No/Not Applicable

18. Success message or error message in a web page, is not passed through the query string ( i.e. passed through the url and it can be changeable by the end user which is not correct)
Yes /No/Not Applicable

19. Logo is clickable and it’s taking to the home page of the website
Yes /No/Not Applicable


20. Main Navigation/Main Menu is present in all of the web pages
Yes /No/Not Applicable

21. Client side validation (Javascript validation) has been done.
Yes /No/Not Applicable

22. Server side validation has been done.
Yes /No/Not Applicable

23. All the data entered in the forms are saved/emailed correctly
Yes /No/Not Applicable

24. Navigation is user friendly
Yes /No/Not Applicable

25. The pages which requires login( the pages can be viewed only after login), are not able visit without login and redirect to login page.
Yes /No/Not Applicable

26. Login page has the “forgot password” link as well as signup link and proper error message has been displayed if the login details are incorrect.
Yes /No/Not Applicable


Note:

Yes – Working

No – Not Working and details need to be mentioned

Not Applicable – If the point has not been checked, it can be mentioned as “Not Applicable” and
Team Leader / Client Manager’s decision will be final to decide about whether this is part of the scope or not and same should be recorded in the testing approval mail if this point has not been checked with details.

This is not the full list and this will get updated frequently and you will be notified of the same. If you have any difficulty or if you have any suggestions, feel free to contact me about the same so that we can sort out and finalize.

This list has to be followed and should be mentioned in the email with proper option with details. I understand this will be difficult initially but this will make sure that our quality will be good and will prevent from major and repeated/basic errors in the websites.

Wednesday, April 21, 2010

Import Email contacts

Import Yahoo Contacts:
<?php
#Copyright 2006 Svetlozar Petrov
#All Rights Reserved
#svetlozar@svetlozar.net
#http://svetlozar.net

#Script to import the names and emails from yahoo contact list

#Globals Section, $location and $cookiearr should be used in any script that uses
# get_contacts function
$location = "";
$cookiearr = array();

#$addopt specifies whether you want to assume that yahoo id's without email addresses
# have @yahoo email. Most do. Leave true if you want to have those emails returned.
# Change to false if you don't want @yahoo.com to be added to yahoo id's
# In that case you'll only get the id's instead of email address for those.
$addopt = true;


#function get_contacts, accepts as arguments $login (the username) and $password
#returns array of: array of the names and array of the emails if login successful
#otherwise returns 1 if login is invalid and 2 if username or password was not specified
function get_contacts($login, $password)
{
#the globals will be updated/used in the read_header function
#read the notes above about $addopt
global $location;
global $cookiearr;
global $ch;
global $addopt;

#check if username and password was given:
if ((isset($login) && trim($login)=="") || (isset($password) && trim($password)==""))
{
#return error code if they weren't
return 2;
}

#initialize the curl session
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://address.yahoo.com");
curl_setopt($ch, CURLOPT_REFERER, "");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

$html = curl_exec($ch);
$matches = array();

#parse the hidden fields from the login form:
preg_match_all('/<input type\="hidden" name\="([^"]+)" value\="([^"]*)">/', $html, $matches);
$values = $matches[2];
$params = "";

$i=0;
foreach ($matches[1] as $name)
{
$params .= "$name=$values[$i]&";
++$i;
}

$login = urlencode($login);
$password = urlencode($password);
#attempt login:
curl_setopt($ch, CURLOPT_URL,"http://login.yahoo.com/config/login?");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params . "login=$login&passwd=$password");
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header');


$html = curl_exec($ch);

#$loginarr = explode("?", $location);

#test if login was successful:
if (!is_array($cookiearr) || !isset($cookiearr['F']))
{
return 1;
}

preg_match('/\.rand=([^"]*)"/si', $html, $matches);
$value = $matches[1];

#go to the address book page
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL,"http://address.mail.yahoo.com/?1&VPC=import_export&A=B&.rand=$value");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

$html = curl_exec($ch);

#parse the yahoo.csv form and submit it:
$matches = array();
preg_match('/name="\.crumb".*?id="crumb2".*?value="([^"]*)"/si', $html, $matches);
$crumb = $matches[1];

preg_match('/\.rand=([^"]*)"/si', $html, $matches);
$rand = $matches[1];


$action = "http://address.yahoo.com/?1&VPC=import_export&A=B&.rand=$rand";
curl_setopt($ch, CURLOPT_URL, $action);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ".crumb=$crumb&VPC=import_export&A=B&submit%5Baction_export_yahoo%5D=Export+Now");
$html = curl_exec($ch);

curl_close ($ch);

#parse the csv file:
$table = explode("\n\"", $html);

array_shift($table);
$maxi = count($table);

$names = array();
$emails = array();
$phones = array(); //cosmin, phones

#parse emails and names:
for($i=0; $i<$maxi; ++$i)
{
$table[$i]=explode(',"',$table[$i]);
$table[$i]=array_map("trimvals", $table[$i]);
#echo '<pre>'; print_r($table[$i]); echo '</pre>'; // cosmin, debug

$names[$i]=trim("{$table[$i][0]} {$table[$i][1]} {$table[$i][2]}");

if($names[$i]=="")
{
$names[$i]=trim($table[$i][3]); //if no name set to nickname
}
if($names[$i]=="")
{
$names[$i]=trim($table[$i][7]); //if no name set to yahooid
}

$emails[$i]=trim($table[$i][4]);
if($emails[$i]=="" && trim($table[$i][7])!="")
{

if ($addopt && !eregi("@", $table[$i][7]) && (trim($table[$i][7])!=""))
$emails[$i]=trim($table[$i][7]) . "@yahoo.com"; //if no email set to yahooid + @yahoo.com
else
$emails[$i]=trim($table[$i][7]);
}

// cosmin, phones
//$phones[$i]=trim($table[$i][4]);
if($phones[$i]=="" && trim($table[$i][12])!="")
{
$phones[$i]=trim($table[$i][12]);
}
}

#return the result:
return array($names, $emails, $phones);
}

#function to trim the whitespace around names and email addresses
#used by get_contacts when parsing the csv file
function trimvals($val)
{
return trim ($val, '" ');
}

#read_header is essential as it processes all cookies and keeps track of the current location url
#leave unchanged, include it with get_contacts
function read_header($ch, $string)
{
global $location;
global $cookiearr;
global $ch;

$length = strlen($string);
if(!strncmp($string, "Location:", 9))
{
$location = trim(substr($string, 9, -1));
}
if(!strncmp($string, "Set-Cookie:", 11))
{
$cookiestr = trim(substr($string, 11, -1));
$cookie = explode(';', $cookiestr);
$cookie = explode('=', $cookie[0]);
$cookiename = trim(array_shift($cookie));
$cookiearr[$cookiename] = trim(implode('=', $cookie));
}
$cookie = "";
if(trim($string) == "")
{
foreach ($cookiearr as $key=>$value)
{
$cookie .= "$key=$value; ";
}
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}

return $length;
}
?>

Gmail Contacts:
<?php
#Copyright 2006 Svetlozar Petrov
#All Rights Reserved
#svetlozar@svetlozar.net
#http://svetlozar.net

#Script to import the names and emails from gmail contact list

#Globals Section, $location and $cookiearr should be used in any script that uses
# get_contacts function
$location = "";
$cookiearr = array();

#function get_contacts, accepts as arguments $login (the username) and $password
#returns array of: array of the names and array of the emails if login successful
#otherwise returns 1 if login is invalid and 2 if username or password was not specified
function get_contacts($login, $password)
{
#the globals will be updated/used in the read_header function
global $location;
global $cookiearr;
global $ch;

#check if username and password was given:
if ((isset($login) && trim($login)=="") || (isset($password) && trim($password)==""))
{
#return error code if they weren't
return 2;
}

#initialize the curl session
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://mail.google.com/mail/");
curl_setopt($ch, CURLOPT_REFERER, "");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header');

#get the html from gmail.com
$html = curl_exec($ch);

$matches = array();
$actionarr = array();

$action = "https://www.google.com/accounts/ServiceLoginAuth?service=mail";

#parse the login form:
#parse all the hidden elements of the form
preg_match_all('/<input type\="hidden" name\="([^"]+)".*?value\="([^"]*)"[^>]*>/si', $html, $matches);
$values = $matches[2];
$params = "";

$i=0;
foreach ($matches[1] as $name)
{
$params .= "$name=" . urlencode($values[$i]) . "&";
++$i;
}

$login = urlencode($login);
$password = urlencode($password);

#submit the login form:
curl_setopt($ch, CURLOPT_URL,$action);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params ."Email=$login&Passwd=$password&PersistentCookie=");

$html = curl_exec($ch);

#test if login was successful:
if (!isset($cookiearr['GX']) && (!isset($cookiearr['LSID']) || $cookiearr['LSID'] == "EXPIRED"))
{
return 1;
}

#this is the new csv url:
curl_setopt($ch, CURLOPT_URL, "http://mail.google.com/mail/contacts/data/export?exportType=ALL&groupToExport=&out=OUTLOOK_CSV");
curl_setopt($ch, CURLOPT_POST, 0);// cosmin, vad ca altfel nu merge...
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

$html = curl_exec($ch);

$csvrows = explode("\n", $html);
array_shift($csvrows);
//echo'<pre>';var_dump($csvrows);echo'</pre>';
$names = array();
$emails = array();
$phones = array();// cosmin, phones
foreach ($csvrows as $row)
{
$values = explode(",", $row);
if (eregi("@", $values[1]))
{
$names[] = ( trim($values[0])=="" ) ? $values[1] : $values [0];
$emails[] = $values[1];
$phones[] = $values[9]; // cosmin, phones
}
}


return array($names, $emails, $phones);
}

#read_header is essential as it processes all cookies and keeps track of the current location url
#leave unchanged, include it with get_contacts
function read_header($ch, $string)
{
global $location;
global $cookiearr;
global $ch;

$length = strlen($string);
if(!strncmp($string, "Location:", 9))
{
$location = trim(substr($string, 9, -1));
}
if(!strncmp($string, "Set-Cookie:", 11))
{
$cookiestr = trim(substr($string, 11, -1));
$cookie = explode(';', $cookiestr);
$cookie = explode('=', $cookie[0]);
$cookiename = trim(array_shift($cookie));
$cookiearr[$cookiename] = trim(implode('=', $cookie));
}
$cookie = "";
if(trim($string) == "")
{
foreach ($cookiearr as $key=>$value)
{
$cookie .= "$key=$value; ";
}
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}

return $length;
}

#function to trim the whitespace around names and email addresses
#used by get_contacts when parsing the csv file
function trimvals($val)
{
return trim ($val, "\" \n");
}
?>

Hotmail Contact
<?php
#Copyright 2006 Svetlozar Petrov
#All Rights Reserved
#svetlozar@svetlozar.net
#http://svetlozar.net

#Script to import the names and emails from hotmail contact list

#Globals Section, $location and $cookiearr should be used in any script that uses
# get_contacts function
$location = "";
$cookiearr = array();
$chget = null;
$chpost = null;
$mspauth = "";
$mspprof = "";

#function get_contacts, accepts as arguments $login (the username) and $password
#returns array of: array of the names and array of the emails if login successful
#otherwise returns 1 if login is invalid and 2 if username or password was not specified
function get_contacts($login, $passwd)
{
global $location;
global $cookiearr;
global $chget;
global $chpost;
$names = array();
$emails = array();

$cookiearr['CkTst']= "G" . time() . "000";

#check if username and password was given:
if ((isset($login) && trim($login)=="") || (isset($passwd) && trim($passwd)==""))
{
#return error code if they weren't
return 2;
}

#hotmail requires to add @hotmail.com when you sign in:
if (!eregi("@", $login))
$login .= "@" . "hotmail.com";

#initialize the curl session
$chget = curl_init();
$chpost = curl_init();

#get the login form:
curl_setopt($chget, CURLOPT_URL,"http://login.live.com/login.srf?id=2");
curl_setopt($chget, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($chget, CURLOPT_REFERER, "");
curl_setopt($chget, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chget, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chget, CURLOPT_HEADERFUNCTION, 'read_header');
$html = curl_exec($chget);

$matches = array();

#parse the hidden fields (logon form):
preg_match_all('/<input type\="hidden"[^>]*name\="([^"]+)"[^>]*value\="([^"]*)">/', $html, $matches);
$values = $matches[2];
$params = "";

$i=0;
foreach ($matches[1] as $name)
{
$params .= "$name=" . urlencode($values[$i]);
++$i;
if(isset($matches[$i]))
{
$params .= "&";
}
}

$params = trim ($params, "&");

curl_setopt($chpost, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chpost, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chpost, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($chpost, CURLOPT_POST, 1);
curl_setopt($chpost, CURLOPT_HEADERFUNCTION, 'read_header');


#parse the login form:
$matches = array();
preg_match('/<form [^>]+action\="([^"]+)"[^>]*>/', $html, $matches);
$opturl = $matches[1];


#parse the hidden fields:
preg_match_all('/<input type="hidden"[^>]*name\="([^"]+)"[^>]*value\="([^"]*)"[^>]*>/', $html, $matches);
$values = $matches[2];
$params = "";


$i=0;
foreach ($matches[1] as $name)
{
$paramsin[$name]=$values[$i];
++$i;
}

#some form specific javascript stuff before submission, this takes care of that:
$sPad="IfYouAreReadingThisYouHaveTooMuchFreeTime";
$lPad=strlen($sPad)-strlen($passwd);
$PwPad=substr($sPad, 0,($lPad<0)?0:$lPad);

$paramsin['PwdPad']=urlencode($PwPad);
foreach ($paramsin as $key=>$value)
{
$params .= "$key=" . urlencode($value) . "&";
}

curl_setopt($chpost, CURLOPT_URL, $opturl);
curl_setopt($chpost, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chpost, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chpost, CURLOPT_POST, 1);
curl_setopt($chpost, CURLOPT_POSTFIELDS, $params . "login=" . urlencode($login) . "&passwd=" . urlencode($passwd) . "&LoginOptions=2");
$html = curl_exec($chpost);


#test for valid login:
if((preg_match('/replace[^"]*"([^"]*)"/', $html, $matches)==0) && (preg_match("/url=([^\"]*)\"/si", $html, $matches)==0 || eregi("password is incorrect", $html)))
{
return 1;
}



#curl_setopt($chget, CURLOPT_URL, $location);
curl_setopt($chget, CURLOPT_URL,$matches[1]);
curl_setopt($chget, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chget, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chget, CURLOPT_HEADERFUNCTION, 'read_header');
$html = curl_exec($chget);


if (eregi("hotmail.msn.com/", $location))
{
#process the non-live interface
#passed the login, you need to load this page to get some more cookies to complete the login
curl_setopt($chget, CURLOPT_URL,"http://cb1.msn.com/hm/header.armx?lid=1033&cbpage=login&lc=1033&x=3.200.4104.0");
curl_setopt($chget, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chget, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chget, CURLOPT_HEADERFUNCTION, 'read_header');
$html = curl_exec($chget);

#follow the javascript redirection url:
curl_setopt($chget, CURLOPT_POST, 0);
curl_setopt($chget, CURLOPT_URL,$matches[1]);
curl_setopt($chget, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chget, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($chget, CURLOPT_HEADERFUNCTION, 'read_header');

$html = curl_exec($chget);

#get the base url and build the url for the page with contacts:
preg_match("/(http:\/\/[^\/]*\/cgi-bin\/).*?curmbox=([^\& ]*).*?a=([^\& ]*)/i", $location, $baseurl);
$url = $baseurl[1] . "AddressPicker?a=$baseurl[3]&curmbox=$baseurl[2]&Context=InsertAddress&_HMaction=Edit&qF=to";

curl_setopt($chget, CURLOPT_URL,$url);
curl_setopt($chget, CURLOPT_USERAGENT, 0);
curl_setopt($chget, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chget, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chget, CURLOPT_HEADERFUNCTION, 'read_header');

$html = curl_exec($chget);

#parse the emails and names:
preg_match_all('/<option.*?value="([^"]*)"[^>]*>(.*?)\</i', $html, $emailarr);


#get rid of duplicates:
$emailsunique = array_unique($emailarr[1]);

$i = 0;
foreach ($emailsunique as $key => $value)
{
$emails[$i] = $emailarr[1][$key];
$names[$i++] = $emailarr[2][$key];
}

#return the result:
return array($names, $emails);
}

global $mspauth;
global $mspprof;
#override cookies for live mail
#this is a quick solution for right now

if (!eregi("@msn", $login))
{
$cookiearr["MSPAuth"] = $mspauth;
$cookiearr["MSPProf"] = $mspprof;

$cookie = "";
foreach ($cookiearr as $key=>$value)
{
$cookie .= "$key=$value; ";
}
$cookie = trim ($cookie, "; ");

curl_setopt($chget, CURLOPT_COOKIE, $cookie);
curl_setopt($chpost, CURLOPT_COOKIE, $cookie);
}


if (preg_match('/location\.replace[^"]*"([^"]*)"/', $html, $matches))
{
curl_setopt($chget, CURLOPT_URL,$matches[1]);
curl_setopt($chget, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chget, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chget, CURLOPT_HEADERFUNCTION, 'read_header');
$html = curl_exec($chget);
}



#new live mail ####################################################################################
if (strpos($html, "TodayLight") > 0)
{
$url = $location; //$matches[1];
$url = explode("/", $url);
$url[sizeof($url)-1] = "options.aspx?subsection=26";
$url = implode("/", $url);
curl_setopt($chget, CURLOPT_URL,$url);
curl_setopt($chget, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chget, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chget, CURLOPT_HEADERFUNCTION, 'read_header');

$html = curl_exec($chget);

preg_match_all('/<input type="hidden"[^>]*name\="([^"]+)"[^>]*value\="([^"]*)"[^>]*>/si', $html, $matches);
$values = $matches[2];
$params = "";


$i=0;
foreach ($matches[1] as $name)
{
$paramsin[$name]=$values[$i];
++$i;
}

$paramsin['ctl01$ExportButton'] = "Export contacts";
$paramsin['mt'] = $cookiearr['mt'];

foreach ($paramsin as $key=>$value)
{
$params .= "$key=" . urlencode($value) . "&";
}

curl_setopt($chpost, CURLOPT_URL, $url);
curl_setopt($chpost, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chpost, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chpost, CURLOPT_POST, 1);
curl_setopt($chpost, CURLOPT_POSTFIELDS, $params);
$html = curl_exec($chpost);


#parse the csv file:
$table = explode("\n", $html);

$separator = ",";
if (count($table)>0)
{
$rowzero = array_shift($table);
if (count(explode(",", $rowzero)) > 10 ) #10 doesn't mean a lot here, could be compared to 1
{
$separator = ",";
}
else
{
$separator = ";";
}
}

$maxi = count($table);

$names = array();
$emails = array();
$phones = array();//cosmin, phones

#parse emails and names:
for($i=0; $i<$maxi; ++$i)
{
$table[$i]=explode($separator,$table[$i]);
#echo '<pre>'; print_r($table[$i]); echo '</pre>'; // cosmin, debug

if (count($table[$i])>46)
{
$names[$i]=trim($table[$i][1],'"') . " " . trim($table[$i][3],'"');
$emails[$i]=trim($table[$i][46],'"');
$phones[$i]=trim($table[$i][25],'"');// cosmin, phones
}
}

#return the result:
return array($names, $emails, $phones);

}
################################################# end new live mail - old live mail below

$url = $matches[1];
$url = explode("/", $url);
$url[count($url)-1] = "ApplicationMainReach.aspx?Control=EditMessage&_ec=1&FolderID=00000000-0000-0000-0000-000000000001";//$matches[1];
$url = implode("/", $url);

curl_setopt($chget, CURLOPT_URL,$url);
curl_setopt($chget, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chget, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chget, CURLOPT_HEADERFUNCTION, 'read_header');

$html = curl_exec($chget);


preg_match_all('/<input.*?type\="?hidden"?.*?name\="([^"]*)".*?value\="([^"]*)"/si', $html, $matches);
$postarr[$matches[1][0]]=($matches[2][0]);
$postarr["query"]= "Find in Mail";
$postarr["ToContact"]= "To:";
$postarr["fTo"]= "";
$postarr["fCC"]= "";
$postarr["fBcc"]= "";
$postarr["fSubject"]= "";
$postarr["fMessageBody"]= "";

curl_setopt($chpost, CURLOPT_URL, $url);
curl_setopt($chpost, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chpost, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chpost, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($chpost, CURLOPT_POST, 1);
curl_setopt($chpost, CURLOPT_POSTFIELDS, $postarr);
curl_setopt($chpost, CURLOPT_HEADERFUNCTION, 'read_header');
$html = curl_exec($chpost);

preg_match_all('/<input type="checkbox" name="contactNameEmail" value="([^;]*);([^"]+)"/si', $html, $matches);

$emails = array_map("arrurldecode", $matches[2]);
$names = array_map("arrurldecode", $matches[1]);

return array($names, $emails);
}

function arrurldecode($val)
{
return urldecode ($val);
}

#read_header is essential as it processes all cookies and keeps track of the current location url
#leave unchanged, include it with get_contacts
function read_header($ch, $string)
{
global $location;
global $cookiearr;
global $chget;
global $chpost;
global $mspauth;
global $mspprof;

$length = strlen($string);
if(!strncmp($string, "Location:", 9))
{

$url = trim(substr($string, 9, -1));
if (eregi("http:", $url))
{
$location = $url;
}
else
{
$matches = array();
preg_match("#(https?\:\/\/[^\/]*)\/#si", $location, $matches);
$location = $matches[0] . $url;
}
}
if(!strncmp($string, "Set-Cookie:", 11))
{
$cookiestr = trim(substr($string, 11, -1));
$cookie = explode(';', $cookiestr);
$cookie = explode('=', $cookie[0]);
$cookiename = trim(array_shift($cookie));

if ($cookiename == "MSPAuth")
{
$mspauth = !empty($cookiearr['MSPAuth']) ? $cookiearr['MSPAuth'] : "";
}

if ($cookiename == "MSPProf")
{
$mspprof = !empty($cookiearr['MSPProf']) ? $cookiearr['MSPProf'] : "";
}

if ($cookiename!=="MSPOK" || !$cookiearr['MSPOK'])
{
$cookiearr[$cookiename] = trim(implode('=', $cookie));
}

}
$cookie = "";
if(trim($string) == "")
{
foreach ($cookiearr as $key=>$value)
{
$cookie .= "$key=$value; ";
}
$cookie = trim ($cookie, "; ");

curl_setopt($chget, CURLOPT_COOKIE, $cookie);
curl_setopt($chpost, CURLOPT_COOKIE, $cookie);
}

return $length;
}

?>

AOL:
<?php
#Copyright 2006 Svetlozar Petrov
#All Rights Reserved
#svetlozar@svetlozar.net
#http://svetlozar.net

#Script to import the names and emails from aol contact list

#Globals Section, $location and $cookiearr should be used in any script that uses
# get_contacts function
$location = "";
$cookiearr = array();

#function get_contacts, accepts as arguments $login (the username) and $password
#returns array of: array of the names and array of the emails if login successful
#otherwise returns 1 if login is invalid and 2 if username or password was not specified
function get_contacts($login, $passwd)
{
global $location;
global $cookiearr;
global $ch;

$login = explode("@", $login);
$login = $login[0];

#check if username and password was given:
if ((isset($login) && trim($login)=="") || (isset($passwd) && trim($passwd)==""))
{
#return error code if they weren't
return 2;
}

#initialize the curl session
$ch = curl_init();

#get the login form:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_REFERER, "");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header');

curl_setopt($ch, CURLOPT_URL, "https://my.screenname.aol.com/_cqr/login/login.psp?mcState=initialized&seamless=novl&sitedomain=sns.webmail.aol.com&lang=en&locale=us&authLev=2&siteState=ver%3a2%7cac%3aWS%7cat%3aSNS%7cld%3awebmail.aol.com%7cuv%3aAOL%7clc%3aen-us");
$html = curl_exec($ch);

#parse the login form:
preg_match('/<form name="AOLLoginForm".*?action="([^"]*).*?<\/form>/si', $html, $matches);
#$opturl = "https://my.screenname.aol.com" .$matches[1];
$opturl = "https://my.screenname.aol.com/_cqr/login/login.psp";

#get the hidden fields:
$hiddens = array();
preg_match_all('/<input type="hidden" name="([^"]*)" value="([^"]*)".*?>/si', $matches[0], $hiddens);
$hiddennames = $hiddens[1];
$hiddenvalues = $hiddens[2];


$hcount = count($hiddennames);
$params = "";
for($i=0; $i<$hcount; $i++)
{
$params .= $hiddennames[$i] . "=" . urlencode($hiddenvalues[$i]) . "&";
}


$login = urlencode($login);
$passwd = urlencode($passwd);

#attempt login:
curl_setopt($ch, CURLOPT_URL, $opturl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params . "loginId=$login&password=$passwd");
$html = curl_exec($ch);



#check if login successful:
if(!preg_match("/'loginForm', 'false', '([^']*)'/si", $html, $matches))
{
#return error if it's not
return 1;
}



$opturl = $matches[1];
curl_close ($ch);
$ch = curl_init();
foreach ($cookiearr as $key=>$value)
{
$cookie .= "$key=$value; ";
}
curl_setopt($ch, CURLOPT_COOKIE, $cookie);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_REFERER, $location);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header');
curl_setopt($ch, CURLOPT_URL, $opturl);
$html = curl_exec($ch);

if (preg_match('/gTargetHost = "([^"]*)".*?gSuccessPath = "([^"]*)"/si', $html, $matches) || preg_match('/gPreferredHost = "([^"]*)".*?gSuccessPath = "([^"]*)"/si', $html, $matches))
{
$opturl = $matches[1];
$opturl .= $matches[2];
$opturl = "http://" . $opturl;
}
else
{
if(preg_match("/'loginForm', 'false', '([^']*)'/si", $html, $matches))
{
$opturl = $matches[1];
curl_setopt($ch, CURLOPT_URL, $opturl);
$html = curl_exec($ch);
$opturl = $location;
}
}


$opturl = explode("/", $opturl);
$opturl[count($opturl)-1]="AB";
$opturl = implode("/", $opturl);

preg_match('/\&uid:([^\&]*)\&/si', $cookiearr['Auth'], $matches);
$usr = $matches[1];

#get the address book:
$opturl .= "/addresslist-print.aspx?command=all&undefined&sort=LastFirstNick&sortDir=Ascending&nameFormat=FirstLastNick&version=$cookiearr[Version]&user=$usr";

curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, $opturl);
$html = curl_exec($ch);
curl_close ($ch);


#parse the emails and names:
preg_match_all('/<span class="fullName">(.*?)<\/span>(.*?)<hr class="contactSeparator">/si', $html, $matches);
$names = $matches[1];
$emails = array_map("parse_emails", $matches[2]);
$phones = array(); //cosmin, phones

#return the result:
return array($names, $emails, $phones);
}

#parse_emails needs to be included to be able to get the emails
function parse_emails($str)
{
$matches = array();
preg_match('/<span>Email 1:<\/span> <span>([^<]*)<\/span>/si', $str, $matches) || preg_match('/<span>Primary Email:<\/span> <span>([^<]*)<\/span>/si', $str, $matches);
return $matches[1];
}


#read_header is essential as it processes all cookies and keeps track of the current location url
#leave unchanged, include it with get_contacts
function read_header($ch, $string)
{
global $location;
global $cookiearr;
global $ch;


$length = strlen($string);
if(!strncmp($string, "Location:", 9))
{
$location = trim(substr($string, 9, -1));
}
if(!strncmp($string, "Set-Cookie:", 11))
{
$cookiestr = trim(substr($string, 11, -1));
$cookie = explode(';', $cookiestr);
$cookie = explode('=', $cookie[0]);
$cookiename = trim(array_shift($cookie));
$cookiearr[$cookiename] = trim(implode('=', $cookie));
}
$cookie = "";
if(trim($string) == "")
{
foreach ($cookiearr as $key=>$value)
{
$cookie .= "$key=$value; ";
}
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}

return $length;
}

?>

MSN:
<?php
#Copyright 2006 Svetlozar Petrov
#All Rights Reserved
#svetlozar@svetlozar.net
#http://svetlozar.net

#Script to import the names and emails from msn contact list

#Globals Section, $location and $cookiearr should be used in any script that uses
# get_contacts function
$location = "";
$cookiearr = array();
$chget = null;
$chpost = null;
$mspauth = "";
$mspprof = "";

#function get_contacts, accepts as arguments $login (the username) and $password
#returns array of: array of the names and array of the emails if login successful
#otherwise returns 1 if login is invalid and 2 if username or password was not specified
function get_contacts($login, $passwd)
{
global $location;
global $cookiearr;
global $chget;
global $chpost;
$names = array();
$emails = array();

$cookiearr['CkTst']= "G" . time() . "000";

#check if username and password was given:
if ((isset($login) && trim($login)=="") || (isset($passwd) && trim($passwd)==""))
{
#return error code if they weren't
return 2;
}

#msn requires to full email address
if (!eregi("@", $login))
$login .= "@" . "msn.com";

#initialize the curl session
$chget = curl_init();
$chpost = curl_init();

#get the login form:
curl_setopt($chget, CURLOPT_URL,"http://login.live.com/login.srf?id=2");
curl_setopt($chget, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($chget, CURLOPT_REFERER, "");
curl_setopt($chget, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chget, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chget, CURLOPT_HEADERFUNCTION, 'read_header');
$html = curl_exec($chget);

$matches = array();

#parse the hidden fields (logon form):
preg_match_all('/<input type\="hidden"[^>]*name\="([^"]+)"[^>]*value\="([^"]*)">/', $html, $matches);
$values = $matches[2];
$params = "";

$i=0;
foreach ($matches[1] as $name)
{
$params .= "$name=" . urlencode($values[$i]);
++$i;
if(isset($matches[$i]))
{
$params .= "&";
}
}

$params = trim ($params, "&");

curl_setopt($chpost, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chpost, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chpost, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($chpost, CURLOPT_POST, 1);
curl_setopt($chpost, CURLOPT_HEADERFUNCTION, 'read_header');


#parse the login form:
$matches = array();
preg_match('/<form [^>]+action\="([^"]+)"[^>]*>/', $html, $matches);
$opturl = $matches[1];


#parse the hidden fields:
preg_match_all('/<input type="hidden"[^>]*name\="([^"]+)"[^>]*value\="([^"]*)"[^>]*>/', $html, $matches);
$values = $matches[2];
$params = "";


$i=0;
foreach ($matches[1] as $name)
{
$paramsin[$name]=$values[$i];
++$i;
}

#some form specific javascript stuff before submission, this takes care of that:
$sPad="IfYouAreReadingThisYouHaveTooMuchFreeTime";
$lPad=strlen($sPad)-strlen($passwd);
$PwPad=substr($sPad, 0,($lPad<0)?0:$lPad);

$paramsin['PwdPad']=urlencode($PwPad);
foreach ($paramsin as $key=>$value)
{
$params .= "$key=" . urlencode($value) . "&";
}

curl_setopt($chpost, CURLOPT_URL, $opturl);
curl_setopt($chpost, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chpost, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chpost, CURLOPT_POST, 1);
curl_setopt($chpost, CURLOPT_POSTFIELDS, $params . "login=" . urlencode($login) . "&passwd=" . urlencode($passwd) . "&LoginOptions=2");
$html = curl_exec($chpost);


#test for valid login:
if((preg_match('/replace[^"]*"([^"]*)"/', $html, $matches)==0) && (preg_match("/url=([^\"]*)\"/si", $html, $matches)==0 || eregi("password is incorrect", $html)))
{
return 1;
}



#curl_setopt($chget, CURLOPT_URL, $location);
curl_setopt($chget, CURLOPT_URL,$matches[1]);
curl_setopt($chget, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chget, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chget, CURLOPT_HEADERFUNCTION, 'read_header');

$html = curl_exec($chget);


if (eregi("hotmail.msn.com/", $location))
{
#process the non-live interface
#passed the login, you need to load this page to get some more cookies to complete the login
curl_setopt($chget, CURLOPT_URL,"http://cb1.msn.com/hm/header.armx?lid=1033&cbpage=login&lc=1033&x=3.200.4104.0");
curl_setopt($chget, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chget, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chget, CURLOPT_HEADERFUNCTION, 'read_header');
$html = curl_exec($chget);

#follow the javascript redirection url:
curl_setopt($chget, CURLOPT_POST, 0);
curl_setopt($chget, CURLOPT_URL,$matches[1]);
curl_setopt($chget, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chget, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($chget, CURLOPT_HEADERFUNCTION, 'read_header');

$html = curl_exec($chget);

#get the base url and build the url for the page with contacts:
preg_match("/(http:\/\/[^\/]*\/cgi-bin\/).*?curmbox=([^\& ]*).*?a=([^\& ]*)/i", $location, $baseurl);
$url = $baseurl[1] . "AddressPicker?a=$baseurl[3]&curmbox=$baseurl[2]&Context=InsertAddress&_HMaction=Edit&qF=to";

curl_setopt($chget, CURLOPT_URL,$url);
curl_setopt($chget, CURLOPT_USERAGENT, 0);
curl_setopt($chget, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chget, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chget, CURLOPT_HEADERFUNCTION, 'read_header');

$html = curl_exec($chget);

#parse the emails and names:
preg_match_all('/<option.*?value="([^"]*)"[^>]*>(.*?)\</i', $html, $emailarr);


#get rid of duplicates:
$emailsunique = array_unique($emailarr[1]);

$i = 0;
foreach ($emailsunique as $key => $value)
{
$emails[$i] = $emailarr[1][$key];
$names[$i++] = $emailarr[2][$key];
}

#return the result:
return array($names, $emails);
}

global $mspauth;
global $mspprof;
#override cookies for live mail
#this is a quick solution for right now

if (!eregi("@msn", $login))
{
$cookiearr["MSPAuth"] = $mspauth;
$cookiearr["MSPProf"] = $mspprof;

$cookie = "";
foreach ($cookiearr as $key=>$value)
{
$cookie .= "$key=$value; ";
}
$cookie = trim ($cookie, "; ");

curl_setopt($chget, CURLOPT_COOKIE, $cookie);
curl_setopt($chpost, CURLOPT_COOKIE, $cookie);
}

if (preg_match('/location\.replace[^"]*"([^"]*)"/', $html, $matches))
{
curl_setopt($chget, CURLOPT_URL,$matches[1]);
curl_setopt($chget, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chget, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chget, CURLOPT_HEADERFUNCTION, 'read_header');
$html = curl_exec($chget);
}

#new live mail ####################################################################################
if (strpos($html, "TodayLight") > 0)
{
$url = $location; //$matches[1];
$url = explode("/", $url);
$url[sizeof($url)-1] = "options.aspx?subsection=26";
$url = implode("/", $url);
curl_setopt($chget, CURLOPT_URL,$url);
curl_setopt($chget, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chget, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chget, CURLOPT_HEADERFUNCTION, 'read_header');

$html = curl_exec($chget);

preg_match_all('/<input type="hidden"[^>]*name\="([^"]+)"[^>]*value\="([^"]*)"[^>]*>/si', $html, $matches);
$values = $matches[2];
$params = "";


$i=0;
foreach ($matches[1] as $name)
{
$paramsin[$name]=$values[$i];
++$i;
}

$paramsin['ctl01$ExportButton'] = "Export contacts";
$paramsin['mt'] = $cookiearr['mt'];

foreach ($paramsin as $key=>$value)
{
$params .= "$key=" . urlencode($value) . "&";
}

curl_setopt($chpost, CURLOPT_URL, $url);
curl_setopt($chpost, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chpost, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chpost, CURLOPT_POST, 1);
curl_setopt($chpost, CURLOPT_POSTFIELDS, $params);
$html = curl_exec($chpost);


#parse the csv file:
$table = explode("\n", $html);

$separator = ",";
if (count($table)>0)
{
$rowzero = array_shift($table);
if (count(explode(",", $rowzero)) > 10 ) #10 doesn't mean a lot here, could be compared to 1
{
$separator = ",";
}
else
{
$separator = ";";
}
}

$maxi = count($table);

$names = array();
$emails = array();
$phones = array();//cosmin, phones

#parse emails and names:
for($i=0; $i<$maxi; ++$i)
{
$table[$i]=explode($separator,$table[$i]);

if (count($table[$i])>46)
{
$names[$i]=trim($table[$i][1],'"') . " " . trim($table[$i][3],'"');
$emails[$i]=trim($table[$i][46],'"');
$phones[$i]=trim($table[$i][25],'"');// cosmin, phones
}
}

#return the result:
return array($names, $emails, $phones);

}
################################################# end new live mail - old live mail below

$url = $matches[1];
$url = explode("/", $url);
$url[count($url)-1] = "ApplicationMainReach.aspx?Control=EditMessage&_ec=1&FolderID=00000000-0000-0000-0000-000000000001";//$matches[1];
$url = implode("/", $url);

curl_setopt($chget, CURLOPT_URL,$url);
curl_setopt($chget, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chget, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chget, CURLOPT_HEADERFUNCTION, 'read_header');

$html = curl_exec($chget);


preg_match_all('/<input.*?type\="?hidden"?.*?name\="([^"]*)".*?value\="([^"]*)"/si', $html, $matches);
$postarr[$matches[1][0]]=($matches[2][0]);
$postarr["query"]= "Find in Mail";
$postarr["ToContact"]= "To:";
$postarr["fTo"]= "";
$postarr["fCC"]= "";
$postarr["fBcc"]= "";
$postarr["fSubject"]= "";
$postarr["fMessageBody"]= "";

curl_setopt($chpost, CURLOPT_URL, $url);
curl_setopt($chpost, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chpost, CURLOPT_RETURNTRANSFER,1);
curl_setopt($chpost, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($chpost, CURLOPT_POST, 1);
curl_setopt($chpost, CURLOPT_POSTFIELDS, $postarr);
curl_setopt($chpost, CURLOPT_HEADERFUNCTION, 'read_header');
$html = curl_exec($chpost);

preg_match_all('/<input type="checkbox" name="contactNameEmail" value="([^;]*);([^"]+)"/si', $html, $matches);

$emails = array_map("arrurldecode", $matches[2]);
$names = array_map("arrurldecode", $matches[1]);

return array($names, $emails);
}

function arrurldecode($val)
{
return urldecode ($val);
}

#read_header is essential as it processes all cookies and keeps track of the current location url
#leave unchanged, include it with get_contacts
function read_header($ch, $string)
{
global $location;
global $cookiearr;
global $chget;
global $chpost;
global $mspauth;
global $mspprof;

$length = strlen($string);
if(!strncmp($string, "Location:", 9))
{

$url = trim(substr($string, 9, -1));
if (eregi("http:", $url))
{
$location = $url;
}
else
{
$matches = array();
preg_match("#(https?\:\/\/[^\/]*)\/#si", $location, $matches);
$location = $matches[0] . $url;
}
}
if(!strncmp($string, "Set-Cookie:", 11))
{
$cookiestr = trim(substr($string, 11, -1));
$cookie = explode(';', $cookiestr);
$cookie = explode('=', $cookie[0]);
$cookiename = trim(array_shift($cookie));

if ($cookiename == "MSPAuth")
{
$mspauth = !empty($cookiearr['MSPAuth']) ? $cookiearr['MSPAuth'] : "";
}

if ($cookiename == "MSPProf")
{
$mspprof = !empty($cookiearr['MSPProf']) ? $cookiearr['MSPProf'] : "";
}

if ($cookiename!=="MSPOK" || !$cookiearr['MSPOK'])
{
$cookiearr[$cookiename] = trim(implode('=', $cookie));
}

}
$cookie = "";
if(trim($string) == "")
{
foreach ($cookiearr as $key=>$value)
{
$cookie .= "$key=$value; ";
}
$cookie = trim ($cookie, "; ");

curl_setopt($chget, CURLOPT_COOKIE, $cookie);
curl_setopt($chpost, CURLOPT_COOKIE, $cookie);
}

return $length;
}

?>

Sending emails through CURL

HTML Form:
<form action="sendmail_contactus.php" method="post" id="form">
<div class="wrapper">
<div class="col-1">
<p>Enter Your Name:</p>
<div class="form1">
<input type="text" name="Name" />
</div>
<p>Enter Your E-mail:</p>
<div class="form1">
<input type="text" name="EmailFrom" />
</div>
<p>Enter Your State:</p>
<div class="form1">
<input type="text" name="State" />
</div>
</div>
<div class="col-2">
<p>Enter Your Message:</p>
<div class="form2">
<textarea cols="1" rows="1" name="Message"></textarea>
</div>
<p class="alignright"><a href="#" class="link" onclick="document.getElementById('form').reset()">clear</a>    
<a href="#" class="link" onclick="document.getElementById('form').submit()">submit</a></p>
</div>
</div>
</form>


CURL Code:
<?php
// the target url which contains scripts that accepts post request
$url = "http://abc.net/abc/contactus.php";

// user agent to mock else defaulted to (HTTPRetriever/1.0)
$useragent="YahooSeeker-Testing/v3.9 (compatible; Mozilla 4.0; MSIE 5.5; http://search.yahoo.com/)";

$ch = curl_init();

// set user agent
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

// set the target url
curl_setopt($ch, CURLOPT_URL,$url);

// howmany parameter to post
curl_setopt($ch, CURLOPT_POST, 1);

// the parameter 'username' with its value 'johndoe'
curl_setopt($ch, CURLOPT_POSTFIELDS,$_POST);


// execute curl,fetch the result and close curl connection
$result= curl_exec ($ch);


/*if(curl_exec($ch) === false)
{
//echo 'Curl error: ' . curl_error($ch);
}
else
{
// echo 'Operation completed without any errors';
}*/

curl_close ($ch);

// display result
//print $result;
header("location:contactus-thanks.html");

?>


Email Script:
if( ($_POST["Name"] != '') && ($_POST["EmailFrom"] != '') && ($_POST["State"] != '') && ($_POST["Message"] != '') )
{

$to = "test@gmail.com";
$from = $_POST["EmailFrom"];

$subject = "Contact Us";

$message = "<B><font color='#CC0000'>Contactus Details</font></B><BR><BR><B><font color='#655112'>Name:</font></B> ".$_POST["Name"]." <BR><BR><B><font color='#655112'>Email From:</font></B>".$_POST["EmailFrom"]."<BR><BR><B><font color='#655112'>State:</font></B> ".$_POST["State"]."<BR><BR><B><font color='#655112'>Message:</font></B> ".$_POST["Message"]."<BR><BR>";


$headers = 'MIME-Version: 1.0'. "\n";
$headers.='Content-type: text/html; charset=iso-8859-1'."\n";
$headers .= "From: $from". "\n";

mail($to,$subject,$message,$headers);
}

QUERY String to FLASH SWF

<?php
if( (isset($_POST['url'])) && (isset($_POST['title'])) && (isset($_POST['autoplay'])) )
{
if($_POST['autoplay'] == 'yes')
{
$autoplay_value = "true";
}
else
{
$autoplay_value = "false";
}

$flash_link = "http://server01/test/musicplayer.swf?mp3url=".$_POST['url']."&txt=".$_POST['title']."&autoplay=".$autoplay_value;


?>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
width="<?php echo $flash_width; ?>" height="22" id="myaudio">
<param name="movie" value="<?php echo $flash_link; ?>" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="<?php echo $flash_link; ?>" quality="high" bgcolor="#ffffff" width="<?php echo $flash_width; ?>" height="22"
name="myaudio" align="" type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer">
</embed>
</object>
<?php
}
?>

JS form validation1

function validate_frm()
{
var URL = document.frm.url.value;
var URL_PARTS =new Array();
URL_PARTS = URL.split('.');
len = URL_PARTS.length
var file_ext = URL_PARTS[len-1];
var arrtitle = new Array();
arrtitle = document.getElementById('title').value.split(" ");
var len = arrtitle.length-1;

var flag1=0;
var iChars3 = "special charssssss";

UL1 = document.frm.url.value;

if(!isValidURL(document.frm.url.value))
{
alert("Please enter valid URL");
document.frm.url.focus();
return false;
}

if( UL1.substring(0,7) != "http://" )
{
alert("Please enter URL with http://");
document.frm.url.focus();
return false;
}

if(file_ext.toLowerCase() != "mp3")
{
alert("Please use mp3 file only.");
document.frm.url.focus();
return false;
}

if(document.frm.title.value=='')
{
alert("Please enter title");
document.frm.title.focus();
return false;
}
else if( ( arrtitle[0] == "") || ( arrtitle[0] == null) )
{
alert("please remove the empty space at begin of the title");
document.getElementById('title').focus();
return false;
}
else if( (arrtitle[len] == "") || (arrtitle[len] == null) )
{
alert("please remove the empty space at end of the title");
document.getElementById('title').focus();
return false;
}
else if( document.getElementById('title').value != "" )
{
for (var i = 0; i < document.getElementById("title").value.length; i++)
{
if (iChars3.indexOf(document.getElementById("title").value.charAt(i)) != -1)
{
flag1=1;
}
}

if(flag1==1)
{
alert ("Title can not accept the following "+iChars3+" characters.");
document.getElementById('title').focus();
return false;
}
}
return true;
}

JS URL Validation

function isValidURL(url){
var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
if(RegExp.test(url)){
return true;
}else{
return false;
}
}

UL1 = document.frm.url.value;

if(!isValidURL(document.frm.url.value))
{
alert("Please enter valid URL");
document.frm.url.focus();
return false;
}

if( UL1.substring(0,7) != "http://" )
{
alert("Please enter URL with http://");
document.frm.url.focus();
return false;
}

Simple Email Script

<?php
//User Tracking Email to administrator
function usertrack($audio_url,$audio_title,$autoplay)
{
$toaddress = "test@gmail.com";
$date_time = date("d-m-Y H:i:s");
$subject = 'Test msg....';
// Html Page message
$message = "
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd >
<html xmlns= http://www.w3.org/1999/xhtml >
<head>
<meta http-equiv= Content-Type content= text/html; charset=iso-8859-1 />
<title>The Team</title>
<style type= text/css >
<!--
.style1 {
color: #CC0066;
font-weight: bold;
}
.style2 {color: #FF00FF}
-->
</style>
</head>
<body>
<table width= 630 border= 0 cellpadding= 0 cellspacing= 0 >
<tr>
<td height= 21 valign= top > </td>
</tr>
<tr>
<td height= 46 valign= top ><strong>Hi Admin , </strong></td>
</tr>
<tr>
<td height= 76 valign= top ><table width= 100% border= 0 cellpadding= 0 cellspacing= 0 >
<tr>
<td width= 28 height= 76 valign= top > </td>
<td width= 602 valign= top >
<b>URL Of where your mp3 is located:</b> ".$audio_url." <br>
<br>
<b>Text to display:</b> ".$audio_title." <br>
<br>
<b>Auto Play:</b> ".$autoplay."<br>
<br>
</td>
</tr>
</table> </td>
</tr>
<tr>
<td height= 15 valign= top > </td>
</tr>
<tr>
<td height= 71 valign= top >
<span class= style2 >The Team! <br /><a href='http://www.gmail.com' target='_blank'>www.gmail.com</a>
<br />
</span></td>
</tr>
</table>
</body>
</html>";

//echo $message;
$headers = 'MIME-Version: 1.0'. "\n";
$headers.='Content-type: text/html; charset=iso-8859-1'."\n";
$headers.='From: The Team <support@gmail.com>'."\n";
mail($toaddress, $subject, $message,$headers);
}

if( (isset($_POST['url'])) && (isset($_POST['title'])) && (isset($_POST['autoplay'])) )
{
$flash_width = strlen($_POST['title'])*12;
$flash_width += 75;
$script="http://server01/test/audioplayer.php?";
$script .="audiourl=".$_POST['url']."&";
$script .="audiotitle=".$_POST['title']."&";
$script .="autoplay=".$_POST['autoplay'];
//echo $script;
$html ="<p align='center'><iframe src='".$script."' width='".$flash_width."' height='85' align='middle' scrolling='no' frameborder='0'></iframe></p>";
usertrack($_POST['url'],$_POST['title'],$_POST['autoplay']);
}
?>

Multi Level Category display


<?php
$link = mysql_connect('localhost', 'root', 'root');
if (!$link) {
die('Not connected : ' . mysql_error());
}

$db_selected = mysql_select_db('libtest', $link);
if (!$db_selected) {
die ('Can\'t use libtest : ' . mysql_error());
}


function menutree($id,$level='0')
{
$level++;

$sql1 = " SELECT count(*) as COUNT1 FROM `menu` WHERE `menu_parent_id` =".$id;
$rs1 = mysql_query($sql1);
$count = mysql_fetch_array($rs1);

if($count["COUNT1"] > 0)
{
$sql2 = "SELECT * FROM `menu` WHERE `menu_parent_id` =".$id." order by menu_name";
$rs2 = mysql_query($sql2);
while( $row2 = mysql_fetch_assoc($rs2) )
{
?>

<option value="<?php echo $row2["menu_id"];?>" <?php if($row2["menu_id"] == $_REQUEST["menu_parent"] ){?> selected <?php } ?>>
<?php

for ($i=0;$i<$level;$i++) {
echo "  ";
}
echo $row2["menu_name"];
?>
</option>
<?php
menutree($row2["menu_id"],$level);
}
}
}
?>

<select name="menu_parent" id="menu_parent" class="input">
<option value="0" <?php if( $_REQUEST["menu_parent"] == 0){ ?> selected <?php } ?>>Root</option>
<?php
$sql = " SELECT * FROM `menu` WHERE `menu_parent_id`=0 order by menu_name";
$rs = mysql_query($sql);
while( $row = mysql_fetch_assoc($rs) )
{
?>
<option value="<?php echo $row["menu_id"];?>" <?php if($row["menu_id"] == $_REQUEST["menu_parent"] ){?> selected <?php } ?>>
<?php echo $row["menu_name"];?>
</option>
<?php
menutree($row["menu_id"],'0');
}
?>
</select>



Database Details:
--
-- Table structure for table `menu`
--

CREATE TABLE `menu` (
`menu_id` int(10) NOT NULL auto_increment,
`mc_id` int(11) NOT NULL default '0',
`menu_name` varchar(150) collate utf8_unicode_ci NOT NULL default '',
`menu_parent_id` int(10) NOT NULL default '0',
`menu_order` int(10) NOT NULL default '0',
`menu_link` varchar(255) collate utf8_unicode_ci NOT NULL default '0',
`menu_pagemode` int(10) NOT NULL default '0',
`menu_created_date` datetime NOT NULL default '0000-00-00 00:00:00',
`menu_modified_date` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`menu_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=48 ;

--
-- Dumping data for table `menu`
--

INSERT INTO `menu` VALUES (1, 1, 'CAREERS', 0, 1, 'index.php/page/index/16', 16, '0000-00-00 00:00:00', '2010-02-05 10:12:23');
INSERT INTO `menu` VALUES (2, 1, 'CONTACT US', 0, 0, 'index.php/page/index/28', 28, '0000-00-00 00:00:00', '2010-02-22 12:21:53');
INSERT INTO `menu` VALUES (3, 1, 'SITEMAP', 0, 0, 'index.php/page/index/49', 49, '0000-00-00 00:00:00', '2010-02-09 04:49:17');
INSERT INTO `menu` VALUES (4, 1, 'UNITED STATES & EUROPE', 1, 1, 'index.php/page/index/43', 43, '0000-00-00 00:00:00', '2010-01-26 09:38:57');
INSERT INTO `menu` VALUES (5, 1, 'INDIA', 1, 2, 'index.php/page/index/44', 44, '0000-00-00 00:00:00', '2010-01-26 09:39:05');
INSERT INTO `menu` VALUES (6, 2, 'HOME', 0, 0, '6', 0, '0000-00-00 00:00:00', '2010-01-22 02:16:35');
INSERT INTO `menu` VALUES (7, 2, 'WHO WE ARE', 0, 0, 'index.php/page/index/52', 52, '0000-00-00 00:00:00', '2010-02-09 02:13:25');
INSERT INTO `menu` VALUES (8, 2, 'WHY CLUTCH GROUP', 0, 0, 'index.php/page/index/51', 51, '0000-00-00 00:00:00', '2010-02-06 07:29:13');
INSERT INTO `menu` VALUES (9, 2, 'OUR SERVICES', 0, 0, 'index.php/page/index/20', 20, '0000-00-00 00:00:00', '2010-02-05 10:12:54');
INSERT INTO `menu` VALUES (10, 2, 'OUR CLIENTS', 0, 0, 'index.php/page/index/21', 21, '0000-00-00 00:00:00', '2010-02-05 10:12:57');
INSERT INTO `menu` VALUES (11, 2, 'RESOURCES', 0, 0, 'index.php/page/index/18', 18, '0000-00-00 00:00:00', '2010-02-05 10:13:01');
INSERT INTO `menu` VALUES (12, 2, 'COMPANY NEWS', 0, 0, 'index.php/page/index/19', 19, '0000-00-00 00:00:00', '2010-02-05 10:13:37');
INSERT INTO `menu` VALUES (13, 2, 'MISSION', 7, 0, 'index.php/page/index/13', 13, '0000-00-00 00:00:00', '2010-02-05 10:13:51');
INSERT INTO `menu` VALUES (14, 2, 'HISTORY', 7, 0, 'index.php/page/index/53', 53, '0000-00-00 00:00:00', '2010-02-05 10:13:56');
INSERT INTO `menu` VALUES (15, 2, 'LEADERSHIP', 7, 0, 'index.php/page/index/22', 22, '0000-00-00 00:00:00', '2010-02-05 10:14:06');
INSERT INTO `menu` VALUES (16, 2, 'AWARDS & RECOGNITIONS', 7, 0, 'index.php/page/index/24', 24, '0000-00-00 00:00:00', '2010-02-05 10:14:12');
INSERT INTO `menu` VALUES (17, 2, 'PARTNERSHIPS', 7, 0, 'index.php/page/index/14', 14, '0000-00-00 00:00:00', '2010-02-05 10:14:21');
INSERT INTO `menu` VALUES (18, 2, 'ORGANIZATIONS', 7, 0, 'index.php/page/index/27', 27, '0000-00-00 00:00:00', '2010-02-05 10:14:30');
INSERT INTO `menu` VALUES (19, 2, 'MANAGEMENT TEAM', 15, 0, 'index.php/page/index/23', 23, '0000-00-00 00:00:00', '2010-02-05 10:15:06');
INSERT INTO `menu` VALUES (20, 2, 'BOARD OF DIRECTORS', 15, 0, 'index.php/page/index/25', 25, '0000-00-00 00:00:00', '2010-02-05 10:15:13');
INSERT INTO `menu` VALUES (21, 2, 'ADVISORY BOARD', 15, 0, 'index.php/page/index/26', 26, '0000-00-00 00:00:00', '2010-02-05 10:15:22');
INSERT INTO `menu` VALUES (22, 2, 'MEET OUR TEAM', 8, 0, 'index.php/page/index/28', 28, '0000-00-00 00:00:00', '2010-02-05 10:15:56');
INSERT INTO `menu` VALUES (23, 2, 'GLOBAL DELIVERY MODEL', 8, 0, 'index.php/page/index/56', 56, '0000-00-00 00:00:00', '2010-02-05 10:16:00');
INSERT INTO `menu` VALUES (24, 2, 'STATE-OF-THE-ART SECURITY', 8, 0, 'index.php/page/index/42', 42, '0000-00-00 00:00:00', '2010-02-05 10:16:05');
INSERT INTO `menu` VALUES (25, 2, 'PROFILES', 22, 0, 'index.php/page/index/54', 54, '0000-00-00 00:00:00', '2010-02-05 10:16:11');
INSERT INTO `menu` VALUES (26, 2, 'LEGAL STAFFING', 9, 0, 'index.php/page/index/41', 41, '0000-00-00 00:00:00', '2010-01-26 09:07:31');
INSERT INTO `menu` VALUES (27, 2, 'DOCUMENT REVIEW', 9, 0, 'index.php/page/index/34', 34, '0000-00-00 00:00:00', '2010-01-26 07:39:02');
INSERT INTO `menu` VALUES (28, 2, 'CONTRACT MANAGEMENT', 9, 0, 'index.php/page/index/33', 33, '0000-00-00 00:00:00', '2010-01-26 07:24:49');
INSERT INTO `menu` VALUES (29, 2, 'COMPLIANCE', 9, 0, 'index.php/page/index/32', 32, '0000-00-00 00:00:00', '2010-01-26 06:49:31');
INSERT INTO `menu` VALUES (30, 2, 'LEGAL RESEARCH', 9, 0, 'index.php/page/index/31', 31, '0000-00-00 00:00:00', '2010-01-26 06:22:56');
INSERT INTO `menu` VALUES (31, 2, 'OFFSHORE REVIEW', 27, 0, 'index.php/page/index/35', 35, '0000-00-00 00:00:00', '2010-01-26 08:04:08');
INSERT INTO `menu` VALUES (32, 2, 'TURN-KEY FACILITIES', 27, 0, 'index.php/page/index/36', 36, '0000-00-00 00:00:00', '2010-01-26 08:16:15');
INSERT INTO `menu` VALUES (33, 2, 'LOW COST MARKETS', 27, 0, 'index.php/page/index/37', 37, '0000-00-00 00:00:00', '2010-01-26 08:21:22');
INSERT INTO `menu` VALUES (34, 2, 'FOREIGN LANGUAGE', 27, 0, 'index.php/page/index/38', 38, '0000-00-00 00:00:00', '2010-01-26 08:32:12');
INSERT INTO `menu` VALUES (35, 2, 'EUROPEAN REVIEW', 27, 0, 'index.php/page/index/39', 39, '0000-00-00 00:00:00', '2010-01-26 08:59:02');
INSERT INTO `menu` VALUES (37, 2, 'DISCOVERY CONSULTING', 27, 0, 'index.php/page/index/40', 40, '0000-00-00 00:00:00', '2010-01-26 09:03:59');
INSERT INTO `menu` VALUES (38, 2, 'CLIENT SUCCESS STORIES', 10, 0, 'index.php/page/index/30', 30, '0000-00-00 00:00:00', '2010-01-26 05:22:52');
INSERT INTO `menu` VALUES (39, 2, 'ETHICS OPINIONS', 11, 0, 'index.php/page/index/29', 29, '0000-00-00 00:00:00', '2010-02-05 10:17:55');
INSERT INTO `menu` VALUES (40, 2, 'PRESS RELEASES', 12, 0, 'index.php/page/index/48', 48, '0000-00-00 00:00:00', '2010-01-27 02:38:26');
INSERT INTO `menu` VALUES (41, 2, 'CLUTCH GROUP IN THE NEWS', 12, 0, 'index.php/page/index/50', 50, '0000-00-00 00:00:00', '2010-02-08 01:15:33');
INSERT INTO `menu` VALUES (42, 2, 'COME SEE US', 12, 0, 'index.php/page/index/55', 55, '0000-00-00 00:00:00', '2010-02-03 02:35:46');
INSERT INTO `menu` VALUES (43, 3, 'TERMS OF USE', 0, 0, 'index.php/page/index/15', 15, '0000-00-00 00:00:00', '2010-02-09 05:32:53');
INSERT INTO `menu` VALUES (44, 3, 'COPYRIGHT NOTICE', 0, 0, 'index.php/page/index/47', 47, '0000-00-00 00:00:00', '2010-02-05 10:18:41');
INSERT INTO `menu` VALUES (45, 3, 'PRIVACY POLICY', 0, 0, 'index.php/page/index/46', 46, '0000-00-00 00:00:00', '2010-02-05 10:18:44');
INSERT INTO `menu` VALUES (46, 3, 'WEBSITE DISCLAIMER', 0, 0, 'index.php/page/index/45', 45, '0000-00-00 00:00:00', '2010-02-05 10:18:47');
INSERT INTO `menu` VALUES (47, 3, 'SITE MAP', 0, 0, 'index.php/page/index/49', 49, '0000-00-00 00:00:00', '2010-02-05 10:18:51');


Monday, April 19, 2010

Zend Test Centers




http://www8.pearsonvue.com/Dispatcher?application=VTCLocator&action=actStartApp&v=W2L&cid=369