PHP/Cpanel - How to create cPanel accounts without 3rd party application? - php

Good evening SO Community,
I've been trying to figure out how to dynamically create a cPanel account with PHP. While doing my pre-question research, I noticed that this question was asked quite a few times, and had a few answers. Unfortunately, the answers that I have found seem to have been depreciated in the latest cPanel versions. I have been trying to get the below script working but had no luck. NOTE: I DID NOT CREATE THE SCRIPT, I JUST FORGOT THE SOURCE. If you know of any way to create cPanel accounts with hosting packages, PLEASE let me know!
<?php
###############################################################
# cPanel WHM Account Creator 1.1
###############################################################
# Visit http://www.zubrag.com/scripts/ for updates
###############################################################
# Required parameters:
# - domain - new account domain
# - user - new account username
# - password - new account password
# - package - new account hosting package (plan)
# - email - contact email
#
# Sample run: create-whm-account.php?domain=reseller.com&user=hosting&password=manager&package=unix_500
#
# If no parameters passed then input form will be shown to enter data.
#
# This script can also be run from another PHP script. This may
# be helpful if you have some user interface already in place and
# want to automatically create WHM accounts from there.
# In this case you have to setup following variables instead of
# passing them as parameters:
# - $user_domain - new account domain
# - $user_name - new account username
# - $user_pass - new account password
# - $user_plan - new account hosting package (plan)
# - $user_email - contact email
#
###############################################################
/////// YOUR WHM LOGIN DATA
$whm_user = "root"; // reseller username
$whm_pass = "PASS"; // the password you use to login to WHM
#####################################################################################
############## END OF SETTINGS. DO NOT EDIT BELOW #######################
#####################################################################################
$whm_host = $_SERVER['HTTP_HOST'];
function getVar($name, $def = '') {
if (isset($_REQUEST[$name]))
return $_REQUEST[$name];
else
return $def;
}
// Domain name of new hosting account
// To create subdomain just pass full subdomain name
// Example: newuser.zubrag.com
if (!isset($user_domain)) {
$user_domain = getVar('domain');
}
// Username of the new hosting account
if (!isset($user_name)) {
$user_name = getVar('user');
}
// Password for the new hosting account
if (!isset($user_pass)) {
$user_pass = getVar('password');
}
// New hosting account Package
if (!isset($user_plan)) {
$user_plan = getVar('package');
}
// Contact email
if (!isset($user_email)) {
$user_email = getVar('email');
}
// if parameters passed then create account
if (!empty($user_name)) {
// create account on the cPanel server
$script = "http://{$whm_user}:{$whm_pass}#{$whm_host}:2086/scripts/wwwacct";
$params = "?plan={$user_plan}&domain={$user_domain}&username={$user_name}&password={$user_pass}&contactemail={$user_email}";
$result = file_get_contents($script.$params);
// output result
echo "RESULT: " . $result;
}
// otherwise show input form
else {
$frm = <<<EOD
<html>
<head>
<title>cPanel/WHM Account Creator</title>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
</head>
<body>
<style>
input { border: 1px solid black; }
</style>
<form method="post">
<h3>cPanel/WHM Account Creator</h3>
<table border="0">
<tr><td>Domain:</td><td><input name="domain" size="30"></td><td>Subdomain or domain, without www</td></tr>
<tr><td>Username:</td><td><input name="user" size="30"></td><td>Username to be created</td></tr>
<tr><td>Password:</td><td><input name="password" size="30"></td><td></td></tr>
<tr><td>Package:</td><td><input name="package" size="30"></td><td>Package (hosting plan) name. Make sure you cpecify existing package</td></tr>
<tr><td>Contact Email:</td><td><input name="email" size="30"></td><td></td></tr>
<tr><td colspan="3"><br /><input type="submit" value="Create Account"></td></tr>
</table>
</form>
</body>
</html>
EOD;
echo $frm;
}
?>
Please let me know if you need any more information!
Thank you in advance,
Tim
EIDT
Source: https://github.com/Ephygtz/cPanel-WHM-automated-account-creator/blob/master/create-whm-account.php
Any ideas?

Good afternoon,
I know this questions is a little dated, but I have found a solution that works for me. Please see below.
<?php
Function createAccount ($newDomain = "", $newUser = "", $newPass = "", $newPlan = "", $newEmail = "") {
$whm_user = "usename";
$whm_pass = "password";
$whm_host = "example.com";
$newDomain = fixData($newDomain);
$newUser = fixData($newUser);
$newPlan = fixData($newPlan);
If (!empty($newUser)) {
// Get new session ID
$sessID = newSession($whm_host, $whm_user, $whm_pass);
$script = "https://www." . $whm_host . ":2087" . $sessID . "/scripts/wwwacct";
$sData = "?plan={$newPlan}&domain={$newDomain}&username={$newUser}&password={$newPass}&contactemail={$newEmail}";
// Authenticate User for WHM access
$context = stream_context_create(array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode("{$whm_user}:{$whm_pass}"),
),
));
// Get result
$result = file_get_contents($script.$sData, false, $context);
//Echo "URL: " . $script.$sData . "<br /><br />";
// Echo "Result: " . $result;
} Else {
Echo "Error: Username is empty!";
}
}
Function newSession($nHost, $nUser, $nPass) { // Example details
$ip = $nHost;
$cp_user = $nUser;
$cp_pwd = $nPass;
$url = "https://$ip:2087/login";
// Create new curl handle
$ch=curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$cp_user&pass=$cp_pwd");
curl_setopt($ch, CURLOPT_TIMEOUT, 100020);
// Execute the curl handle and fetch info then close streams.
$f = curl_exec($ch);
$h = curl_getinfo($ch);
curl_close($ch);
// If we had no issues then try to fetch the cpsess
if ($f == true and strpos($h['url'],"cpsess"))
{
// Get the cpsess part of the url
$pattern="/.*?(\/cpsess.*?)\/.*?/is";
$preg_res=preg_match($pattern,$h['url'],$cpsess);
}
// If we have a session then return it otherwise return empty string
return (isset($cpsess[1])) ? $cpsess[1] : "";
}
Function fixData($data) {
$data = str_replace("-","%2D",$data);
$data = str_replace(".","%2E",$data);
$data = str_replace(" ","%20",$data);
return $data;
}
Function returnData($data) {
$data = str_replace("%2D","-",$data);
$data = str_replace("%2E",".",$data);
$data = str_replace("%20"," ",$data);
return $data;
}
header('Location: https://www.example.com/users');
?>

Related

How to login to girisv3.itu.edu.tr with php/curl?

I am trying to login this website över mu website (i.e localhost)
https://girisv3.itu.edu.tr/Login.aspx
According to example code shared at here for facebook login on other website (localhost)
PHP cURL to login to facebook
I am trying to apply this Facebook login for itu.edu.tr login. But it didnt work. I am also newbie to curl and php. How can I do that for this website (itu.edu.tr)?
<?php
$username = 'username#itu.edu.tr';
$password = 'password';
$loginUrl = 'https://girisv3.itu.edu.tr/Login.aspx';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $loginUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'ContentPlaceHolder1_tbUserName='.$username.'&ContentPlaceHolder1_tbPassword='.$password.'&ContentPlaceHolder1_btnLogin=Login');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://www.itu.edu.tr");
//execute the request
$content = curl_exec($ch);
echo $content;
?>
the login system at girisv3.itu.edu.tr has little in common with the facebook login system (i can say that with confidence because i've studied facebook's login system and written code that logs into facebook )
to login here, first hit https://girisv3.itu.edu.tr/Login.aspx with a simple HTTP GET request, here you'll be redirected 5 times (why? no friggin idea, albeit at least 2 of them are to test that you have cookies enabled) with HTTP Location-redirects , on the first redirect you will get a cookie looking like Set-Cookie: ASP.NET_SessionId=fzwd05uqv2ogyvj2p4ip2x3u; path=/; HttpOnly, save that and re-use it on all following redirects (if you do not, you will get an error like The ITU Introduction application uses cookies. Your browser has been found to block cookies. Please allow cookies from the browser settings and try again later.), and on the last request you will get a cookie looking like Cookie: ASP.NET_SessionId=nmhigw3julmzbedva0zwklj2; cookieCheck=true, this is the cookie you need to actually log in. (cookieCheck=true probably means that you passed the cookie test), once you're finished with the redirects, the HTML contains a lot of data that you need to parse out to log in, a <form element contains a unique url specific to your cookie where you need to send the POST request to log in, it looks like
<form method="post" action="./Login.aspx?subSessionId=543cf6e7-d262-46f3-8207-740d92298bd3&currentURL=https%3a%2f%2fportal.itu.edu.tr%2flogin.aspx%3fReturnUrl%3d%252fapps%252fdefault%252f&cookieAdded=true" id="form1">
and there are a bunch of <input> elements containing data that you also need to parse out and add to the actual login request, specifically
__VIEWSTATE and __VIEWSTATEGENERATOR and __EVENTVALIDATION and ctl00$ContentPlaceHolder1$hfAppName and ctl00$ContentPlaceHolder1$hfToken and ctl00$ContentPlaceHolder1$hfVerifier and ctl00$ContentPlaceHolder1$hfCode and ctl00$ContentPlaceHolder1$hfState and (this 1 is the login username by the way) ctl00$ContentPlaceHolder1$tbUserName
and (this 1 is the login password) ctl00$ContentPlaceHolder1$tbPassword and ctl00$ContentPlaceHolder1$btnLogin
once you have the login POST data parsed out from the html, add the login username to ctl00$ContentPlaceHolder1$tbUserName and add the login password to ctl00$ContentPlaceHolder1$tbPassword, and send the actual login request to the url obtained from the <form element together with the cookie received in the last http-redirect, the data must be encoded in the application/x-www-form-urlencoded-format (and PHP has a native function for encoding php arrays in application/x-www-form-urlencoded-format called http_build_query)
here is an example with hhb_curl (a php curl_ api wrapper which takes care of error detection (turning silent curl errors into RuntimeExceptions), cookies, following Location redirects, freeing curl resources, and then some)
<?php
declare (strict_types = 1);
const USERNAME = "TheUsername";
const PASSWORD = "ThePassword";
require_once('hhb_.inc.php');
$hc = new hhb_curl('', true);
$html = $hc->exec('https://girisv3.itu.edu.tr/Login.aspx')->getStdOut();
$domd = #DOMDocument::loadHTML($html);
$xp = new DOMXPath($domd);
$loginForm = $domd->getElementById("form1");
$login_url = 'https://girisv3.itu.edu.tr/' . $loginForm->getAttribute("action");
$postDataInputNames = array(
'__VIEWSTATE',
'__VIEWSTATEGENERATOR',
'__EVENTVALIDATION',
'ctl00$ContentPlaceHolder1$hfAppName',
'ctl00$ContentPlaceHolder1$hfToken',
'ctl00$ContentPlaceHolder1$hfVerifier',
'ctl00$ContentPlaceHolder1$hfCode',
'ctl00$ContentPlaceHolder1$hfState',
'ctl00$ContentPlaceHolder1$tbUserName',
'ctl00$ContentPlaceHolder1$tbPassword',
'ctl00$ContentPlaceHolder1$btnLogin',
);
$postData = [];
foreach ($postDataInputNames as $name) {
$ele = $xp->query('.//input[#name=' . xpath_quote($name) . ']', $loginForm);
if (!$ele->length) {
var_dump($html);
throw new \LogicException("failed to find input form {$name}!");
}
$ele = $ele->item(0);
$postData[$name] = $ele->getAttribute("value");
}
$postData['ctl00$ContentPlaceHolder1$tbUserName'] = USERNAME;
$postData['ctl00$ContentPlaceHolder1$tbPassword'] = PASSWORD;
var_dump('login post data: ', $postData);
$html = $hc->setopt_array(array(
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => http_build_query($postData),
CURLOPT_URL => $login_url,
))->exec()->getStdOut();
$domd = #DOMDocument::loadHTML('<?xml encoding="UTF-8">' . $html);
$xp = new DOMXPath($domd);
$loginError = $domd->getElementById("ContentPlaceHolder1_lbHata");
if ($loginError && !empty(trim($loginError->textContent))) {
echo "LOGIN ERROR: " . trim($loginError->textContent) . "\n";
} else {
echo "Login success! ";
var_dump($html);
}
//based on https://stackoverflow.com/a/1352556/1067003
function xpath_quote(string $value) : string
{
if (false === strpos($value, '"')) {
return '"' . $value . '"';
}
if (false === strpos($value, '\'')) {
return '\'' . $value . '\'';
}
// if the value contains both single and double quotes, construct an
// expression that concatenates all non-double-quote substrings with
// the quotes, e.g.:
//
// concat("'foo'", '"', "bar")
$sb = 'concat(';
$substrings = explode('"', $value);
for ($i = 0; $i < count($substrings); ++$i) {
$needComma = ($i > 0);
if ($substrings[$i] !== '') {
if ($i > 0) {
$sb .= ', ';
}
$sb .= '"' . $substrings[$i] . '"';
$needComma = true;
}
if ($i < (count($substrings) - 1)) {
if ($needComma) {
$sb .= ', ';
}
$sb .= "'\"'";
}
}
$sb .= ')';
return $sb;
}
which yields:
LOGIN ERROR: Kullanıcı adı veya şifre hatalı.
which means the username/password is invalid, because apparently TheUsername and ThePassword is not valid login credentials.
all the information required to login can be obtained by installing Fiddler Proxy, and record logging in with a browser (like FireFox), and then replicate the browser login procedure with php/curl, which is basically what i did here.

curl command not working on bigrock server…?

<?php
if(isset($_POST["submit"]))
{
$adm=$_POST["admno"];
$phn=$_POST["phn1"];
include("model.php");
$db = new database;
$r=$db->register($adm);
while($row=mysql_fetch_array($r))
{
if($row["phn_no1"]==$phn || $row["phn_no2"]==$phn || $row["phn_no3"]==$phn)
{
$formatted = "".substr($phn,6,10)." ";
$password = $formatted + $adm;
echo $password;
$db->setpassword($adm,$password);
$pre = 'PREFIX';
$suf = '%20ThankYou';
$sms = $pre.$password.$suf;
session_start();
$ch = curl_init("http://www.perfectbulksms.in/Sendsmsapi.aspx? USERID=ID&PASSWORD=PASS&SENDERID=SID&TO=$phn&MESSAGE=$sms");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
$result = curl_exec($ch);
curl_close($ch);
header("Location:password.php?msg=new");
}
else
{
header("Location:register.php?msg=invalid");
}
}
}
?>
this code is working perfect on my local host .. but when i put it on server ... it takes lots of time but the code in curl command is not working it only refers to next page ... i checked that curl is enabled .. if i use only sms api without curl command it sends sms immidiately.... but i want to run both header and also want to hide my sms api.... is there any alternate of this ???

WHMCS error occured: Invalid IP ::1, when using External API

I am trying out GetClient Password on External API
<?php
$url = "http://localhost:81/whmcs/includes/api.php"; # URL to WHMCS API file goes here
$username = "admin"; # Admin username goes here
$password = "pass"; # Admin password goes here
$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["action"] = "GetClientPassword";
$postfields["userid"] = "1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$data = curl_exec($ch);
curl_close($ch);
$data = explode(";",$data);
foreach ($data AS $temp) {
$temp = explode("=",$temp);
$results[$temp[0]] = $temp[1];
}
if ($results["result"]=="success") {
echo "Success<br />
<br />
";
# Result was OK!
} else {
# An error occured
echo "The following error occured: ".$results["message"];
}
?>
Getting an error
result=error;message=Invalid IP ...
I already added the IP in General Setting -> Security Tab.
Note: I am trying this on localhost (xampp)
What am I missing here?
This error means the API Access Key has not been added successfully to the configuration.php file. Please refer to step 7 above. The $api_access_key line should go before the closing ?> tag.
Source
You can also whitelist your IP by following
Setup>General>Security>API IP Access Restriction
if you have a account on whmcs, you will have to white-list the IP Address from where you want to access the api. it's a kind of security measure used by the whmcs team so as not to allow an unauthorized user use one's api. i hope this is helpful. Thanks
Alternatively an access key can be configured to allow IP restrictions to be bypassed.
It works by defining a secret key/passphrase in the WHMCS configuration.php file which is then passed into all API calls. To configure it, add a line as follows to your configuration.php file in the root WHMCS directory.
$api_access_key = 'secret_key_passphrase_goes_here';
Following the introduction of an API Access Key, you can then include it in your API requests as follows:
?action=xxxx&username=xxx&password=xxx&accesskey=secret_key_passphrase_goes_here
More Infos:
https://developers.whmcs.com/api/access-control/

execute external page while doing some function with php?

hello im trying to create a simple script which will create an account with my dedicated server using WHM
here is the simple code
<?php
// your WHM username
$whm_user = 'root';
// your WHM password
$whm_pass = 'pass';
// your WHM hostname
$whm_host = '10.10.10.10';
// new account domain or subdomain name
$user_domain = 'example.com';
// new account username (8 characters or less)
$user_name = 'example';
// new account password
$user_pass = 'example1245';
// new account contact email
$user_email = 'user#example.net';
// new account plan (must be an existing WHM plan)
$user_plan = 'Gold';
// create the account
$site = "https://{$whm_user}:{$whm_pass}#{$whm_host}:2087/scripts/wwwacct";
$params = "?plan={$user_plan}";
$params .= "&domain={$user_domain}";
$params .= "&username={$user_name}";
$params .= "&password={$user_pass}";
$params .= "&contactemail={$user_email}";
$url = $site.$params;
file_get_contents($url);
?>
this return an error
[function.file-get-contents]: failed to open stream: No error in C:\AppServ\www\cp\create-whm-account.php on line 35
then i tried to use CURL
<?php
// your WHM username
$whm_user = 'root';
// your WHM password
$whm_pass = 'pass';
// your WHM hostname
$whm_host = '10.10.10.10';
// new account domain or subdomain name
$user_domain = 'example.com';
// new account username (8 characters or less)
$user_name = 'example';
// new account password
$user_pass = 'example1245';
// new account contact email
$user_email = 'user#example.net';
// new account plan (must be an existing WHM plan)
$user_plan = 'Gold';
// create the account
$site = "https://{$whm_user}:{$whm_pass}#{$whm_host}:2087/scripts/wwwacct";
$params = "?plan={$user_plan}";
$params .= "&domain={$user_domain}";
$params .= "&username={$user_name}";
$params .= "&password={$user_pass}";
$params .= "&contactemail={$user_email}";
$url = $site.$params;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
?>
it doesn't return any error and doesn't work neither
i don't need to return any output as this will work within another functions so i don't need to show any result just create the account within the background
I noticed that you are requesting a HTTPS URL. Extra CURL flags might be required. Very likely:
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
See also: PHP: Curl to fetch html page from HTTPS

How to use Constant Contact API?

I want to use API of the constant contact and want to insert user email using PHP while user register to the site.
please reply if any help.
Thanks in advance.
// fill in your Constant Contact login and API key
$ccuser = 'USERNAME_HERE';
$ccpass = 'PASS_HERE';
$cckey = 'APIKEY_HERE';
// fill in these values
$firstName = "";
$lastName = "";
$emailAddr = "";
$zip = "";
// represents the contact list identification number(s)
$contactListId = INTEGER_OR_ARRAY_OF_INTEGERS_HERE;
$contactListId = (!is_array($contactListId)) ? array($contactListId) : $contactListId;
$post = new SimpleXMLElement('<entry></entry>');
$post->addAttribute('xmlns', 'http://www.w3.org/2005/Atom');
$title = $post->addChild('title', "");
$title->addAttribute('type', 'text');
$post->addChild('updated', date('c'));
$post->addChild('author', "");
$post->addChild('id', 'data:,none');
$summary = $post->addChild('summary', 'Contact');
$summary->addAttribute('type', 'text');
$content = $post->addChild('content');
$content->addAttribute('type', 'application/vnd.ctct+xml');
$contact = $content->addChild('Contact');
$contact->addAttribute('xmlns', 'http://ws.constantcontact.com/ns/1.0/');
$contact->addChild('EmailAddress', $emailAddr);
$contact->addChild('FirstName', $firstName);
$contact->addChild('LastName', $lastName);
$contact->addChild('PostalCode', $zip);
$contact->addChild('OptInSource', 'ACTION_BY_CUSTOMER');
$contactlists = $contact->addChild('ContactLists');
// loop through each of the defined contact lists
foreach($contactListId AS $listId) {
$contactlist = $contactlists->addChild('ContactList');
$contactlist->addAttribute('id', 'http://api.constantcontact.com/ws/customers/' . $ccuser . '/lists/' . $listId);
}
$posturl = "https://api.constantcontact.com/ws/customers/{$ccuser}/contacts";
$authstr = $cckey . '%' . $ccuser . ':' . $ccpass;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $posturl);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $authstr);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/atom+xml"));
curl_setopt($ch, CURLOPT_HEADER, false); // Do not return headers
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); // If you set this to 0, it will take you to a page with the http response
$response = curl_exec($ch);
curl_close($ch);
// returns true on success, false on error
return (!is_numeric($response));
The developers of ConstantContact have launched PHP library to handle such kind of tasks.
Following version is for older PHP versions (5.2 or lesser). Download code from here: https://github.com/constantcontact/ctct_php_library
Following is an example to add a subscriber's email in your constant contact lists.
After downloading the above library, use following code to add an email in Constant Contact list(s).
session_start();
include_once('ConstantContact.php'); // Set path accordingly
$username = 'YOUR_CONSTANT_CONTACT_USER_NAME';
$apiKey = 'YOUR_API_KEY';
$password = 'YOUR_CONSTANT_CONTACT_PASSWORD';
$ConstantContact = new Constantcontact("basic", $apiKey, $username, $password);
$emailAddress = "new_email#test.com";
// Search for our new Email address
$search = $ConstantContact->searchContactsByEmail($emailAddress);
// If the search did not return a contact object
if($search == false){
$Contact = new Contact();
$Contact->emailAddress = $emailAddress;
//$Contact->firstName = $firstName;
//$Contact->lastName = $lastName;
// represents the contact list identification link(s)
$contactList = LINK_OR_ARRAY_OF_LINKS_HERE;
// For example,
// "http://api.constantcontact.com/ws/customers/USER_NAME/lists/14";
$Contact->lists = (!is_array($contactList)) ? array($contactList) : $contactList;
$NewContact = $ConstantContact->addContact($Contact);
if($NewContact){
echo "Contact Added. This is your newly created contact's information<br /><pre>";
print_r($NewContact);
echo "</pre>";
}
} else {
echo "Contact already exist.";
}
Note: The latest version can be found on the GitHub links given in following URL: http://developer.constantcontact.com/libraries/sample-code.html
But I am not sure if the above example code works with the newer library or not.
If you can't get this to work, you might have to add this curl_setopt:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

Categories