We are adding Moodle to our site (different server, different sub-domain, but same main domain, and the servers are set up to be able to communicate with each other) and wha
So I was able to get this resolved and thought I would share my solution in case anybody else has a similar problem in the future.
Since our Moodle site and main site are on the same domain, what I did was in the login script for our main site, I added the following code:
$postData = array('username' => $username, 'password' => $password);
$post = http_post_fields('http://moodle.example.com/login/index.php', $postData);
$headers = http_parse_headers($post);
foreach($headers['Set-Cookie'] as $cookie)
{
$details = http_parse_cookie($cookie);
foreach ($details->cookies as $name => $value)
setcookie($name, $value, $details->expires, $details->path, 'example.com');
}
Basically, I posted the login credentials to the moodle login script using http_post_fields, although cURL should work as well, parsed the headers to get the cookies Moodle set, then set those cookies myself using the basic domain instead of the more specific Moodle subdomain. This can cause some issues if the user has an existing cookie from the more specific subdomain, so be sure to delete any existing cookie with a name of MoodleSession.