38c38
<     $base_url = str_replace('http://', 'https://', $base_url);
---
>     securepages_set_secure_base();
86a87,92
>   $form['securepages_secure_host'] = array(
>     '#type' => 'textfield',
>     '#title' => t('Use a different host (base_url) or port for secured pages'),
>     '#default_value' => variable_get('securepages_secure_host',''),
>     '#description' => t("Have secure pages served from a different host or non-standard port. This allows for shared secure servers to be used or multiple virtual hosts under one IP. To specify an alternate port, enter it's number only.<p><small>After updating this setting, the page may not update correctly. Navigate back here manually to confirm all is good.</small></p>"),
>   );
217c223
<     $url = preg_replace('/^http:\/\//i', 'https://', $url);
---
>     $url = securepages_make_secure($url);
220c226
<     $url = preg_replace('/^https:\/\//i', 'http://', $url);
---
>     $url = securepages_make_standard($url);
286c292,294
<   $url = 'https://'. preg_replace(';^http[s]?://;s', '', url('admin/settings/securepages/test', NULL, NULL, TRUE));
---
>   //This needs some more testing
>   $url = securepages_make_secure(url('admin/settings/securepages/test', NULL, NULL, TRUE));
292a301,378
> /**
>  * Secure Pages Alternate Host Extentions
>  */
> 
> /**
>  * securepages_set_secure_base()
>  *
>  * Set the base_url which should be used when serving secured pages.
>  * If an alternate is present the origial base_url is stored as 
>  * GLOBALS[standard_base_url] to be used later.
>  * If no alternate specified the standard base_url will be used
>  * and converted to https.
>  */
> function securepages_set_secure_base() {
>   global $base_url;
>   $bases = str_replace('http://','https://',Array($base_url,securepages_get_secure_base()));
>   if($bases[0]==$bases[1]){
>     $base_url = $bases[0];  
>   }
>   else {
>     $GLOBALS['standard_base_url'] = $base_url;
>     $base_url = $bases[1];
>   }
> }
> 
> /**
>  * securepages_get_secure_base()
>  *
>  * Get the base_url which should be used to serve secured pages.
>  *
>  * @return The correct base_url to use for secure pages
>  */
> function securepages_get_secure_base() {
>   global $base_url;
>   $base = $base_url;
>   $alternate = variable_get('securepages_secure_host', false);
>   if($alternate){
>     //Should we just append a port number or should we replace the whole base_url?
>     $base = is_numeric($alternate) ? $base.':'.$alternate : $alternate; 
>   }
>   return str_replace('http://','https://',$base);
> }
> 
> /**
>  * securepages_get_standard_base()
>  *
>  * Get the base_url which should be used to serve standard pages.
>  *
>  * @return The base_url to use when serving normal pages. The same as base_url in settings.php (if specified)
>  */
> function securepages_get_standard_base() {
>   global $standard_base_url, $base_url; 
>   return str_replace('https://','http://',($standard_base_url?$standard_base_url:$base_url));
> }
> 
> /**
>  * securepages_make_secure()
>  *
>  * Change the host and protocol of a link to point to a secure resource on 
>  * the correct host or port.
>  *
>  * @return Secure path to resourse
>  */
> function securepages_make_secure ($url) {
>   return str_replace(securepages_get_standard_base(),securepages_get_secure_base(),$url);
> }
> 
> /**
>  * securepages_make_standard()
>  *
>  * Change the host and protocol of a link to point to an unencrypted resourse
>  * on the standard host.
>  *
>  * @return Unsecure path to resourse
>  */
> function securepages_make_standard ($url) {
>   return str_replace(securepages_get_secure_base(),securepages_get_standard_base(),$url);
> }
