[pmwiki-users] Getting ssl to work with the http: to https: forcing script?

Patrick R. Michaud pmichaud at pobox.com
Mon Jan 22 11:15:22 CST 2007


On Mon, Jan 22, 2007 at 04:58:00PM +0000, Clive Shane Hetherington wrote:
> 
> Hi People,
> 
> I am working with the auto convert from http: to https: cookbook script:
> 
> $ScriptUrl = str_replace('http:','https:',$ScriptUrl,1);
> $PubDirUrl = str_replace('http:','https:',$PubDirUrl,1);
> if ($_SERVER['SERVER_PORT'] != 443) {
>    if (!@$pagename) { header("Location: $ScriptUrl");
>    } else { Redirect($pagename); }
> }
> 
> However I come up with the following errors:
> 
> Warning: Wrong parameter count for str_replace() in 
> /home/wholesou/public_html/wholesoulclients/farmtest/local/config.php on line 19

Remove the "1" parameter from the call to str_replace -- i.e., use:

    $ScriptUrl = str_replace('http:','https:',$ScriptUrl);
    $PubDirUrl = str_replace('http:','https:',$PubDirUrl);
    if ($_SERVER['SERVER_PORT'] != 443) {
       if (!@$pagename) { header("Location: $ScriptUrl");
       } else { Redirect($pagename); }
    }

(The fourth parameter to str_replace is available only in PHP 5 and
later.  Also, the fourth parameter doesn't limit the number of
replacements performed, but is a return-value to count how many
replacements were performed.)

Note that PmWiki version 2.2.0-beta18 and later automatically
detect https: and use it accordingly.  So, with 2.2.0 you
can do:

    if ($UrlScheme != 'https:') {
      $ScriptUrl = str_replace($UrlScheme, 'https:', $ScriptUrl);
      if (!@$pagename) { header("Location: $ScriptUrl"); exit; }
      Redirect($pagename);
    }

Pm




More information about the pmwiki-users mailing list