edgedata Posted September 10, 2006 Share Posted September 10, 2006 Hey, I run a phpBB with a few private forums and would like to give my users an easy way to switch between SSL and HTTP. Here's some psuedo-code that will hopefully give you guys an idea of what I mean:[code]//IIRC, php should have an operator to return each part of the URL. create var "Link_to" create var "Address" if [Protocol] == "http://", var "Link_to" is assigned the value of "Secure" and var "Address" the value of "https://mysite.com/" else var "Link_to" is assigned the value of "Unsecure" and var "Address" the value of "http://mysite.com:2006" //link should read: <a href="{"Address"+"Current path"}">"Link_to"</a>[/code] Quote Link to comment Share on other sites More sharing options...
edgedata Posted September 10, 2006 Author Share Posted September 10, 2006 Bump. Quote Link to comment Share on other sites More sharing options...
btherl Posted September 10, 2006 Share Posted September 10, 2006 It does have an operator (well, a function), called parse_url(). I agree though that it can be hard to find php functions sometimes.Try checking $_SERVER['SCRIPT_URI'] for the the full URL of your script (that's URI, not URL).So, something like[code]$url_parts = parse_url($_SERVER['SERVER_URI']);if ($url_parts['scheme']) == 'http') { $link_to = 'secure'; $address = preg_replace('|^http|', 'https', $_SERVER['SERVER_URI']);} else { $link_to = 'insecure'; $address = preg_replace('|^https|', 'http', $_SERVER['SERVER_URI']);}echo "<a href=\"$address\">$link_to</a>";[/code]The meaning of that preg_replace() is to replace "http" with "https" (or the other way around for the second one), but ONLY at the start (that's why the "^" is there, it means "at the start). The "|" is just a marker for the start and end of the expression, it has no special meaning. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.