Solved

http or https in PHP

Posted on 2013-05-13
3
313 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 108

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now