Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 164283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:43:00+00:00 2026-05-11T11:43:00+00:00

So kind of very similar to Detecting https requests in php : Want to

  • 0

So kind of very similar to ‘Detecting https requests in php‘:

Want to have https://example.com/pog.php go to http://example.com/pog.php or even vice versa.

Problems:

  • Can’t read anything from $_SERVER[‘HTTPS’] since it’s not there
  • Server is sending both requests over port 80, so can’t check for 443 on the HTTPS version
  • apache_request_headers() and apache_response_headers() are sending back the same thing
  • Can’t tell the loadbalancer anything or have it send extra somethings
  • Server feedback data spat out by the page on both URL calls is exactly the same save for the session ID. Bummer.

Are there any on page ways to detect if it’s being called via SSL or non-SSL?

Edit: $_SERVER['HTTPS'] isn’t there, switched on or not, no matter if you’re looking at the site via SSL or non-SSL. For some reason the hosting has chosen to serve all the HTTPS requests encrypted, but down port 80. And thusly, the $_SERVER['HTTPS'] is never on, not there, just no helpful feedback on that server point. So that parameter is always be empty.

(And yeah, that means it gets flagged in say FF or Chrome for a partially invalid SSL certificate. But that part doesn’t matter.)

Also, the most that can be gotten from detecting the URL is up to the point of the slashes. The PHP can’t see if the request has https or http at the front.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:43:00+00:00Added an answer on May 11, 2026 at 11:43 am

    Keyword — Load Balancer

    The problem boils down to the fact that the load balancer is handling SSL encryption/decryption and it is completely transparent to the webserver.

    Request:  Client -> 443or80 -> loadbalancer -> 80 -> php Response: PHP -> 80 -> loadbalancer -> 443or80 -> Client 

    The real question here is ‘do you have control over the load balancer configuration?’


    If you do, there are a couple ways to handle it. Configure the load balancer to have seperate service definitions for HTTP and HTTPS. Then send HTTP traffic to port 80 of the web servers, and HTTPS traffic to port 81 of the webservers. (port 81 is not used by anything else).

    In apache, configure two different virtual hosts:

    <VirtualHost 1.2.3.4:80>    ServerName foo.com    SetEnv USING_HTTPS 0    ... </VirtualHost>  <VirtualHost 1.2.3.4:81>    ServerName foo.com    SetEnv USING_HTTPS 1    ... </VirtualHost> 

    Then, the environment variable USING_HTTPS will be either 1|0, depending on which virtual host picked it up. That will be available in the $_SERVER array in PHP. Isn’t that cool?


    If you do not have access to the Load Balancer configuration, then things are a bit trickier. There will not be a way to definitively know if you are using HTTP or HTTPS, because HTTP and HTTPS are protocols. They specify how to connect and what format to send information across, but in either case, you are using HTTP 1.1 to make the request. There is no information in the actual request to say if it is HTTP or HTTPS.

    But don’t lose heart. There are a couple of ideas.

    The 6th parameter to PHP’s setcookie() function can instruct a client to send the cookie ONLY over HTTPS connections (http://www.php.net/setcookie). Perhaps you could set a cookie with this parameter and then check for it on subsequent requests?

    Another possibility would be to use JavaScript to update the links on each page depending on the protocol (adding a GET parameter).

    (neither of the above would be bullet proof)

    Another pragmatic option would be to get your SSL on a different domain, such as secure.foo.com. Then you could resort to the VirtualHost trick above.


    I know this isn’t the easiest issue because I deal with it during the day (load balanced web cluster behind a Cisco CSS load balancer with SSL module).

    Finally, you can always take the perspective that your web app should switch to SSL mode when needed, and trust the users NOT to move it back (after all, it is their data on the line (usually)).

    Hope it helps a bit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 104k
  • Answers 104k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try Observer pattern. If the dependencies between the observers start… May 11, 2026 at 8:38 pm
  • Editorial Team
    Editorial Team added an answer One thing you could try is the Tanuki Wrapper: http://wrapper.tanukisoftware.org/doc/english/download.jsp… May 11, 2026 at 8:38 pm
  • Editorial Team
    Editorial Team added an answer A circular buffer is the best answer. It is the… May 11, 2026 at 8:38 pm

Related Questions

Working on a particular application, I keep writing very similar queries, again and again.
I'm getting in to a situation where I have several interacting widgets (on a
Currently, i have basic C++ and PHP skills. But, i want to switch to
I'm writing some software that targets two versions of very similar hardware which, until

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.