?
Solved

http or https in PHP

Posted on 2013-05-13
3
Medium Priority
?
325 Views
Last Modified: 2013-05-14
Hi

How can I check if the current URL is HTTP or https or tcp in PHP?
0
Comment
Question by:KaranGupta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 23

Accepted Solution

by:
tailoreddigital earned 2000 total points
ID: 39163540
0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 39163626
You also mentioned "or tcp" but that is a bit vague. HTTP and HTTPS are protocols that sit on top of TCP. TCP defines the method of transmitting data, while HTTP and HTTPS define the content of that data.

So if you have some other type of protocol you want to check besides HTTP or HTTPS, you'll have to spell it out.

Also, if you're referring to things like something://blah blah and somethingelse://etc, then you should know that the <something>:// prefix of a URL is not really sent to the server, so the server doesn't know what it is. The <something> simply tells your computer how to treat everything after the ://, so when you have a URL like https://site.com, your computer sees "https" and knows that "https" is handled by a web browser, so your web browser takes over and does the rest.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39164368
Install this script, shown here in its entirety and run it with both HTTP and HTTPS.  Look in the output near the bottom for $_SERVER["HTTPS"].
<?php phpinfo();

Open in new window

Usually this test is sufficient to make a real-time programmatic determination
if (empty($_SERVER["HTTPS"])) { 
    $protocol = 'http://'; 
} else { 
    $protocol = 'https://'; 
}

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The viewer will learn how to count occurrences of each item in an array.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question