- if ($basepath != System::baseUrl() && !strstr($dest, '/magic') && !strstr($dest, '/rmagic')) {
- $magic_path = $basepath . '/magic' . '?f=&owa=1&dest=' . $dest;
- $serverret = Network::curl($magic_path);
- if (!empty($serverret['success'])) {
- goaway($magic_path);
- }
- }
+ // We need to extract the basebath from the profile url
+ // to redirect the visitors '/magic' module.
+ // Note: We should have the basepath of a contact also in the contact table.
+ $urlarr = explode('/profile/', $contact['url']);
+ $basepath = $urlarr[0];
+
+ if ($basepath != $a->getBaseURL() && !strstr($dest, '/magic') && !strstr($dest, '/rmagic')) {
+ $magic_path = $basepath . '/magic' . '?f=&owa=1&dest=' . $dest;
+
+ // We have to check if the remote server does understand /magic without invoking something
+ $serverret = Network::curl($basepath . '/magic');
+ if ($serverret->isSuccess()) {
+ Logger::log('Doing magic auth for visitor ' . $my_url . ' to ' . $magic_path, LOGGER_DEBUG);
+ System::externalRedirect($magic_path);