This class is used to add data to existing MySpace.com user profile using PHP cURL. User is authenticated with their login information and data - in form of plain text or HTML code - is saved with the existing profile data. User selects the section of their profile where the data is to be added by this class.
Version 1.0, Created 04/09/2006
Author - Ehsan Haque
Web - http://ehsan.bdwebwork.com/
Bug Fixed & Updated by - MA Razzaque Rupom
Web - http://www.rupom.info
/*
Set to true if HTTP proxy is required to browse net
- Setting it to true will require to provide Proxy Host Name and Port number
*/
$myspace->isUsingProxy = false;
// Set the Proxy Host Name
$myspace->proxyHost = "";
// Set the Proxy Port Number
$myspace->proxyPort = "";
// Set the location to save the Cookie Jar File
$myspace->cookieJarPath = $_SERVER['DOCUMENT_ROOT'] . "/MySpace/";
/*
Execute the Service
- Require to pass MySpace.com Account Username and Password
*/
$execute = $myspace->execService($email, $password, $section, $data);
if (!empty($myspace->errorInfo))
{
echo $myspace->errorInfo;
return false;
}
/*--------------------------------------------------------------------------
About the class - class.MySpace.php
This class is used to add data to existing MySpace.com user profile using
PHP cURL. User is authenticated with their login information and data
- in form of plain text or HTML code - is saved with the existing profile
data. User selects the section of their profile where the data is to be
added by this class.
Version 1.0, Created 04/09/2006
Author - Ehsan Haque
Web - http://ehsan.bdwebwork.com/
Bug Fixed & Updated by - MA Razzaque Rupom
Web - http://www.rupom.info
/*--------------------------------------------------------------------------
Public Variables - Alphabetical List
+ cookieJarPath ---------------- Absolute path to write Cookie file
+ data ---------------- Data to be added
+ email ---------------- Email for Login
+ isUsingProxy ---------------- Specifies if the server is using proxy
+ password ---------------- Password for Login
+ proxyHost ---------------- Host address for proxy
+ proxyPort ---------------- Port number for proxy
+ section ---------------- Section to add data
--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------
Private Variables - Alphabetical List
+ addDataURI ---------- URL to be used to post data
+ allData ---------- Existing profile data from MySpace.com
+ cookie ---------- Set to 1 (true) if cookie is to be used
in header
+ cookieFile ---------- Temporary cookie file name
+ cookieFileJar ---------- Temporary file where cookie is saved
+ follow ---------- Set to 1 (true) if header redirection(s)
are to be performed
+ getDataURI ---------- URL to retrieve existing data
+ loginURI ---------- URL for login to MySpace.com
+ postFields ---------- Set the fields to be sent via POST as name=value
+ proxy ---------- Proxy server address as host:port
+ referer ---------- Referer URL used by cURL
+ returnTransfer ---------- Set to 1 (true) if the output is to
saved in as a string
+ sectionFieldName ---------- Form field name for selected section
+ showHeader ---------- Set to 1 (true) if header information
is to be printed in the output
+ statusMsg ---------- Success or Failure message
+ url ---------- URL to be used by cURL
+ userAgent ---------- User agent used by cURL
+ usePostField ---------- Set to 1 (true) if any data is
sent via POST
--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------
Functions - Alphabetical List
--------------------------------------------------------------------------*/
class MySpace
{
/*--------------------------------------------------------------------------
Public Variables
--------------------------------------------------------------------------*/
/**
* MySpace.com Email address for login
* @public
* @var string
*/
var $email = "";
/**
* MySpace.com Password for login
* @public
* @var string
*/
var $password = "";
/**
* MySpace.com Section for data addition
* @public
* @var string
*/
var $section = "";
/**
* Data that is to be added to MySpace.com selected Section
* @public
* @var string
*/
var $data = "";
/**
* Abosolute path to save the cookie
* Default value is DOCUMENT_ROOT
* @public
* @var string
*/
var $cookieJarPath = "";
/**
* Specifies if Proxy server required as Gateaway
* Default value is false
* @public
* @var boolean
*/
var $isUsingProxy = false;
/**
* Proxy host name
* @public
* @var string
*/
var $proxyHost = "";
/**
* Proxy port number
* @public
* @var int
*/
var $proxyPort = 0;
/**
* URL to Authenticate user on MySpace.com
* @private
* @var string
*/
var $loginURI = "http://login.myspace.com/index.cfm?fuseaction=login.process&MyToken=f806380a-c55b-42d1-8535-9508c24d50c5";
/**
* URL to Authenticate user on MySpace.com
* @private
* @var string
*/
var $addDataURI = "http://profileedit.myspace.com/Modules/ProfileEdit/Pages/Interests.aspx?fuseaction=profile.interests&MyToken=f9420a7d-1a88-46c7-8dee-5765c85d15ba";
/**
* URL to Authenticate user on MySpace.com
* @private
* @var string
*/
var $getDataURI = "http://profileedit.myspace.com/Modules/ProfileEdit/Pages/Interests.aspx?fuseaction=profile.interests&MyToken=f9420a7d-1a88-46c7-8dee-5765c85d15ba";
/**
* URL to be used by cURL
* @private
* @var string
*/
var $url = "";
/**
* User agent (used to trick Yahoo!)
* @private
* @var string
*/
var $userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6";
/**
* Referer URL (used to trick Yahoo!)
* @private
* @var string
*/
var $referer = "http://www.myspace.com";
/**
* Specifies whether output includes the header
* @private
* @var int
*/
var $showHeader = 0;
/**
* Specifies if cURL should follow the redirected URL
* @private
* @var int
*/
var $follow = 0;
/**
* Specifies if cURL should save the output to a string
* @private
* @var int
*/
var $returnTransfer = 1;
/**
* Specifies number of post fields to pass
* @private
* @var int
*/
var $usePostField = 0;
/**
* Specify fields to send via POST method as key=value
* @private
* @var string
*/
var $postFields = "";
/**
* All profile data from MySpace.com
* @private
* @var array
*/
var $allData = array();
/**
* Specify field name for the selected Section
* @private
* @var string
*/
var $sectionFieldName = "";
/**
* File where Cookie is temporarily saved
* @private
* @var string
*/
var $cookieFileJar = "";
/**
* Cookie File that is read by service process
* This carries same value as $cookieFileJar
* @private
* @var string
*/
var $cookieFile = "";
/**
* Specifies if Cookie is to be in header
* @private
* @var int
*/
var $cookie = 0;
/**
* Proxy address as proxy.host:port
* @private
* @var string
*/
var $proxy = "";
/**
* Status message as found from the profile update page
* @private
* @var string
*/
var $statusMsg = "";
/*--------------------------------------------------------------------------
Function Definitions
--------------------------------------------------------------------------*/
/**
* Executes the Service
* @param string $login Username of user's MySpace.com Account
* @param string $password Password of the user's MySpace.com Account
* @param string $section Section where user's information will be added
* @param string $data Data that is to be added to the selected section
* @return array|false
*/
function execService($email, $password, $section, $data)
{
$email = trim($email);
$password = trim($password);
if (empty($email))
{
$this->setError("provide_email");
return false;
}
if (empty($password))
{
$this->setError("provide_pass");
return false;
}
if (empty($section))
{
$this->setError("select_section");
return false;
}
if (empty($data))
{
$this->setError("empty_data");
return false;
}
// Sets the URL depending on the choosen service
switch ($this->section)
{
case 'aboutme' : $this->sectionFieldName .= "AboutMeText"; break;
case 'liketomeet' : $this->sectionFieldName .= "LikeToMeetText"; break;
case 'general' : $this->sectionFieldName .= "GeneralText"; break;
case 'music' : $this->sectionFieldName .= "MusicText"; break;
case 'movies' : $this->sectionFieldName .= "MoviesText"; break;
case 'television' : $this->sectionFieldName .= "TelevisionText"; break;
case 'books' : $this->sectionFieldName .= "BooksText"; break;
case 'heroes' : $this->sectionFieldName .= "HeroesText"; break;
}
}
/**
* Authenticates user on MySpace.com
* @return boolean
*/
function doAuthentication()
{
// Instructs to initialize cURL session
$this->initCurl();
// Sets the URL for authentication purpose
$this->url = $this->loginURI;
// Sets the number of fields to send via HTTP POST
$this->usePostField = 1;
// Sets the fields to be sent via HTTP POST as key=value
$this->postFields = "email=$this->email&password=$this->password&ctl00$Main$SplashDisplay$login$loginbutton=&Remember=";
$this->follow = 1;
// Instructs to set Cookie Jar
$this->setCookieJar();
// Checks if the cURL options are all set properly
if ($this->setCurlOption())
{
// Instructs to execute cURL session
$this->execCurl();
// Checks if any cURL error is generated
if ($this->getCurlError())
{
$this->unlinkFile($this->cookieFileJar);
$this->setError("curl_error");
return false;
}
// Checks if the authentication failed, either invalid login or username is not registered
if (preg_match("/Must Be Logged-In/i", $this->outputContent))
{
// Instructs to close cURL session
$this->closeCurl();
// Unlinks the cookie file
$this->unlinkFile($this->cookieFileJar);
$this->setError("invalid_login");
return false;
}
$this->closeCurl();
}
unset($this->outputContent);
return true;
}
/**
* Adds the profile data on MySpace.com
* @return array|false
*/
function doAddData()
{
$this->getAllData();
if (empty($this->allData))
{
$this->setError("profile_data_empty");
return false;
}
/**
* Sets the Cookie Jar File where Cookie is temporarily saved
* @return void
*/
function setCookieJar()
{
// Sets the encrypted cookie filename using MySpace.com account username
$this->cookieFilename = MD5($this->email);
// Sets the Cookie Jar filename with an absolute path
$this->cookieFileJar = (!empty($this->cookieJarPath)) ? $this->cookieJarPath . "/" . $this->cookieFilename : $_SERVER['DOCUMENT_ROOT'] . "/" . $this->cookieFilename;
fopen($this->cookieFileJar, "w");
}
/**
* Sets cURL options
* @return boolean
*/
function setCurlOption()
{
// Sets the User Agent
curl_setopt($this->curlSession, CURLOPT_USERAGENT, $this->userAgent);
// Sets the HTTP Referer
curl_setopt($this->curlSession, CURLOPT_REFERER, $this->referer);
// Sets the URL that PHP will fetch using cURL
curl_setopt($this->curlSession, CURLOPT_URL, $this->url);
// Sets the number of fields to be passed via HTTP POST
curl_setopt($this->curlSession, CURLOPT_POST, $this->usePostField);
// Sets the fields to be sent via HTTP POST as key=value
curl_setopt($this->curlSession, CURLOPT_POSTFIELDS, $this->postFields);
// Sets the filename where cookie information will be saved
curl_setopt($this->curlSession, CURLOPT_COOKIEJAR, $this->cookieFileJar);
// Sets the filename where cookie information will be looked up
curl_setopt($this->curlSession, CURLOPT_COOKIEFILE, $this->cookieFile);
// Sets the option to set Cookie into HTTP header
curl_setopt($this->curlSession, CURLOPT_COOKIE, $this->cookie);
//curl_setopt($this->curlSession, CURLOPT_SSL_VERIFYPEER,false);
// Checks if the user needs proxy (to be set by user)
if ($this->isUsingProxy)
{
// Checks if the proxy host and port is specified
if ((empty($this->proxyHost)) || (empty($this->proxyPort)))
{
$this->setError("proxy_required");
$this->unlinkFile($this->cookieFileJar);
return false;
}
// Sets the proxy address as proxy.host:port
$this->proxy = $this->proxyHost . ":" . $this->proxyPort;
}
// Sets the proxy server as proxy.host:port
curl_setopt($this->curlSession, CURLOPT_PROXY, $this->proxy);
// Specifies whether to save the output to a string
curl_setopt($this->curlSession, CURLOPT_RETURNTRANSFER, $this->returnTransfer);
curl_setopt($this->curlSession, CURLOPT_CAINFO, $this->caBundleFile);
// Specifies whether to use all header redirections
curl_setopt($this->curlSession, CURLOPT_FOLLOWLOCATION, $this->follow);