Thanks very much, Dirk. That did the trick.
For the curious, all I had to do was instruct cURL to store cookie data in a file.
Text Formatted Code
// create a cookie jar
$cookie_filename = 'cookie_jar.txt';
$file = fopen ($cookie_filename, "w");
fclose ($file);
// initialize cURL
$connection = curl_init ();
curl_setopt ($connection, CURLOPT_COOKIEJAR, $cookie_filename);
curl_setopt ($connection, CURLOPT_COOKIEFILE, $cookie_filename);
curl_setopt ($connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt ($connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt ($connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($connection, CURLOPT_POST, true);
// log in to the web log as "App Helper"
$post_data = array ();
$post_items = array ();
$post_data['loginname'] = 'App Helper';
$post_data['passwd'] = 'password';
$post_data['submit'] = 'Login';
foreach ($post_data as $key => $value)
{
$post_items[] = $key . '=' . $value;
}
$post_string = implode ('&', $post_items);
curl_setopt ($connection, CURLOPT_URL, 'http://mysite.com/blog/users.php');
curl_setopt ($connection, CURLOPT_POSTFIELDS, $post_string);
$result = curl_exec ($connection);
if ($result !== false)
{
// login succeeded
// create a new post in the "Recruiting" forum
$post_data = array ();
$post_items = array ();
$post_data['forum'] = '7';
$post_data['id'] = '0';
$post_data['modedit'] = '0';
$post_data['method'] = 'newtopic';
$post_data['editpost'] = '';
$post_data['editpid'] = '';
$post_data['editid'] = '';
$post_data['page'] = '0';
$post_data['name'] = 'App Helper';
$post_data['subject'] = 'subject of post';
$post_data['comment'] = 'content of post';
$post_data['notify'] = '';
$post_data['postmode'] = 'text';
$post_data['submit'] = 'Submit';
foreach ($post_data as $key => $value)
{
$post_items[] = $key . '=' . $value;
}
$post_string = implode ('&', $post_items);
curl_setopt ($connection, CURLOPT_URL, 'http://mysite.com/blog/forum/createtopic.php');
curl_setopt ($connection, CURLOPT_POSTFIELDS, $post_string);
$result = curl_exec ($connection);
if ($result === false)
{
// post creation failed
log_event ("ERROR: curl_exec (create post) returned FALSE");
}
}
else
{
// login failed
log_event ("ERROR: curl_exec (log in) returned FALSE");
}
Thanks again, Dirk. You are the man!