GithubHelp home page GithubHelp logo

Comments (6)

upsonp avatar upsonp commented on August 20, 2024

I think so. I'll have to look to be sure, but I think there's a $_SERVER['SERVER_PROTOCOL'] that should probably be used in stead of 'http://'.

The PHP documentation is a little vague on what 'SERVER_PROTOCOL' does. From PHP.net

'SERVER_PROTOCOL'
Name and revision of the information protocol via which the page was requested; i.e. 'HTTP/1.0';

If not, I'm sure there are other ways we can make this work.

from wet-boew-php.

upsonp avatar upsonp commented on August 20, 2024

Turns out it's quite a bit of effort to setup SSL for Apache on either Linux or Windows. @crochefort Could you make the change on your local copy and test this possible fix out?

I found a PHP variable that indicates if HTTPS is on or off.

I'd like to see Line 9 replaced with:

$protocal = "http://";
if( $_SERVER["HTTPS"] == 'on' ) {
   $protocal = "https://";
}
$q = $protocal . $SERVER['HTTPHOST'] . $SERVER['QUERYSTRING'];

When it's working we'll put it up in the repository.

from wet-boew-php.

michael-milette avatar michael-milette commented on August 20, 2024

I believe there are several flaws with the following line than just missing support for both http and https:

$q = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['QUERY_STRING'];

HTTP_HOST resolves to the domain of the server.

QUERY_STRING resolves to the parameters after the ? in the URL

ISSUE 1: There is no question mark between the domain and the parameters. So, if the host is canada.ca and my query string is lang=en, it will build the following URL:

 http://canada.calang=en

ISSUE 2: The path and the page are missing from the URL. For example, if I am currently on the http://canada.ca/contact?lang=en page, the above code will turn this into http://canada.calang=en which is not going to help you switch language.

ISSUE 3: There is no support for port numbers. For example, if the page we are accessing is http://canada.ca:8081/contact?lang=en, the above code will once again turn this into:

 http://canada.calang=en

ISSUE 4: As mentioned by crochefort, there is no support for HTTPS.

ISSUE 5: There is no support for fragments. For example, if the page we are accessing is http://canada.ca#footer, the above code will convert this to http://canada.ca. Unfortunately this last one can only be resolved using client-side JavaScript as the hash and fragment are not sent to the server.

As for the rest, if you don't mind my making a suggestion, consider replacing the above code with something like this:

$protocol = 'http';
$port = '';
if ($_SERVER['SERVER_PORT'] == 443 || (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')) {
    $protocol .= 's';
} elseif ($_SERVER['SERVER_PORT'] != 80) {
    $port = ':'.$_SERVER['SERVER_PORT'];
}
$q = $protocol . '://' . $_SERVER['HTTP_HOST'] . $port . $_SERVER['REQUEST_URI'];

Hope that helps.

Best regards,

Michael

from wet-boew-php.

crochefort avatar crochefort commented on August 20, 2024

I just try the one from @michael-milette and Chrome give me the error .. too many redirect.

The one from @upsonp is working great on my Dev.

On my Dev I have a non-valid SSL certificat and it's working fine.

from wet-boew-php.

upsonp avatar upsonp commented on August 20, 2024

Thanks to both of you for trying this out.

I guess I'm just going to have to break down and figure out how to install SSL for my dev servers so I can do some testing. Maybe sometime really early next year ;)

from wet-boew-php.

crochefort avatar crochefort commented on August 20, 2024

Closing since no longer revelant with the new script

from wet-boew-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.