I take it that your approach of retrieving and then reconstructing the list of HTTP parameters will solve the sessionID issue I was having? I figured it was something pretty basic but I do not do HTTP hacking so I didn't know how to do this.
<?php
/* LCsub.php --
Purpose: Remote List Control via HTTP, subscribe function
Original Author: Rich Cowan, 8/8/05
Modified by: Jesse Heap 1/3/2006
Details:
With PHPList installed this procedure can be use to
subscribe a user using the HTTP command. The procedure works
by simulating a POST to the default subscribe page. It requires
the CURL PHP library.
LCsub.php -- will subscribe a user
USAGE:
(we assuming list #1, master password is "plist")
Command:
http://mydomain.com/lists/LCsub.php?pwd=plist&email=johndoe%40aol.com
Result:
This will subscribe John Doe to the email list; note that the
'@' sign has been replaced here by %40 which is needed by most
web servers.
Command:
http://mydomain.com/lists/LCsub.php?pwd=plist&email=johndoe@aol.com&attribute1=John&attribute2=Doe&attribute3=TX
Result:
This will subscribe John Doe to the email list, but also add
user data for him, namely John's first name, last name, and
state, which must be set up as phplist attributes for List #2
INSTALLATION AND CONFIGURATION:
Just copy this script to the home directory of phplist, the lists folder.
To make it executable (on Linux), do a 'chmod 755 phplist'
To configure, just replace the values below for settings with the
location of your phplist installation, and a working admin password
for this installation.
Questions? Feel free to email me, richcowan <at> gmail.com
*/
// GLOBAL VARIABLES
// CONFIGURATION SETTINGS. Set them up for your host
$domain = "http://www.yoursite.com/lists/";
$lid = 1; // lid is the default PHPlist List ID to use
$masterpassword = "yourmasterpassword"; // Master password prevents unauthorized calls to script
$login = "admin"; // phplist admin Login
$pass = "yourphpplistassword"; // phplist admin password
$skipConfirmationEmail = 1; // Set to 0 if you require a confirmation email to be sent.
// CODE
//TODO: Put in check to only allow script to be called from authorized domains
// 1) Retrieve the password parameter supplied in http request
$pwd = $_GET['pwd'];
if ($pwd == $masterpassword) { // make sure password matches
echo("Master Password was correct.<br>"); //debug code, ok to remove
// 2) if script password is correct, then retrieve other parameters
$ary = explode('&', $_SERVER['QUERY_STRING']);
$i = 0;
$post_data = array();
while ($i < count($ary)) {
$getArray = split('=', $ary[$i]);
// Set each GET value pair to the post_data associative array in preperation for the POST
if (strcasecmp(urldecode($getArray[0]),'pwd')!=0) { // Ignore PWD parameter - not needed for POST
$post_data[urldecode($getArray[0])] = urldecode($getArray[1]);
}
$i++;
}
// Ensure email is provided
$email = $post_data['email'];
$tmp = $_GET['lid'];
if ($tmp != '') {$lid = $tmp; } //user may override default list ID
if ($email == '') {
echo('You must supply an email address');
return(0);
}
// 3) Login to phplist as admin and save cookie using CURLOPT_COOKIEFILE
$url = $domain . "admin/?";
$ch = curl_init();
$login_data = array();
$login_data["login"] = $login;
$login_data["password"] = $pass;
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $login_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/nofileneeded.txt"); //Enable Cookie Parser. File does not need to exist - http://curl.netmirror.org/libcurl/c/libcurl-tutorial.html for more info
$result = curl_exec($ch);
// echo("Result was: $result<br>"); //debug
// 3) Now simuulate post to subscriber form.
$post_data["emailconfirm"] = $email;
$post_data["htmlemail"] = "1";
$post_data["list[$lid]"] = "signup";
$post_data["listname[$lid]"] = "test";
$post_data["subscribe"] = "Subscribe";
$post_data["makeconfirmed"] = $skipConfirmationEmail; //If set to 1 it will confirm user bypassing confirmation email
$url = $domain . "?p=subscribe";
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
echo("Result was: $result<br>");
//6) Clean up
curl_close($ch);
} // end of if clause
else {
echo("Password not supplied.");
}
// close the php tag
?>
Phplist class
A set of functions which provide a simple way to interact with phpList in your own programs (eg: adding a user who just purchased something from your website to a mailing list). It takes a list id, an email address, and optionally some attributes, and subscribes the user to that list. If the user already exists, the existing account will be subscribed. If it's a new user, they'll be added first. Users added in this way are pre-confirmed (they will not be sent a confirmation email).
Source: http://docs.phplist.com/PhplistHacks
H2B2 wrote:Though not using http, this set of related functions might be useful:
Phplist class
purplemine wrote:How is everyone calling this from a form, for example. I'm hoping to integrate into several different places and looking for some options!
Thanks,
John
$post_data["htmlemail"] = "1";
$tmp=explode("_",$_GET["lists"]);
foreach ($tmp as $value)
{
$post_data["list[$value]"] = "signup";
}
$post_data["listname[$lid]"] = "test";
Return to Contributions: Plug-ins, Add-ons, Mods
Users browsing this forum: No registered users and 0 guests