Solved

http or https in PHP

Posted on 2013-05-13
3
318 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
3 Comments
 
LVL 23

Accepted Solution

by:
tailoreddigital earned 500 total points
ID: 39163540
0
 
LVL 34

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 109

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

808 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