Solved

Use HTTPS instead of HTTP in apache

Posted on 2014-11-24
10
276 Views
Last Modified: 2014-11-29
Hi,

I have created a webpage using PHP to telnet into the router. But instead of the regular http access I want to access the same webpage using https. I have installed the wampserver software.

How can I achieve that?
0
Comment
Question by:Vipin Kumar
[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
10 Comments
 
LVL 11

Expert Comment

by:Radek Baranowski
ID: 40462853
If I understand you right, you have a piece of php code which connects to a telnet port on some remote server, right ?

Now, the secure version of telnet is ssh - secure shell. Therefore you might use ssh2 function to open ssh connection to remote server, example is given here:

http://php.net/manual/en/function.ssh2-connect.php

there are many ssh2 functions in default PHP, the full list is here:

http://php.net/manual/en/book.ssh2.php

If you would like to authenticate with username and password, you are most likely to use this one:

http://php.net/manual/en/function.ssh2-auth-password.php  <- check out the example from this page:

<?php
$connection = ssh2_connect('shell.example.com', 22);

if (ssh2_auth_password($connection, 'username', 'secret')) {
  echo "Authentication Successful!\n";
} else {
  die('Authentication Failed...');
}
?>

Open in new window


cheers, hope this helps
0
 
LVL 29

Expert Comment

by:Jan Springer
ID: 40462886
if you want https, for that site or that page (whichever you prefer), use mod_rewrite to write any http header into https within your httpd.conf.
0
 
LVL 30

Assisted Solution

by:Kerem ERSOY
Kerem ERSOY earned 500 total points
ID: 40463388
Hi,

As far as I understand you want to redirect your PHP page to HTTPS if it was requested with HTTP. If you add this code snippet in the beginning of your code it would redirect the page to HTTP is launcehed with HTTP:

<?php
if(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == ""){
    $redirect = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    header("Location: $redirect");
}
?>

Open in new window


If you want to redirect all your web server to https you can add this directive to your document root in httpd.conf:

Redirect permanent / https://www.mydomain.com/

Open in new window



Cheers,
K.
0
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 
LVL 1

Author Comment

by:Vipin Kumar
ID: 40463613
@ Jan Springer

How do i implement mod_rewrite to use https instead of http?
0
 
LVL 1

Author Comment

by:Vipin Kumar
ID: 40463617
@ Kerem ERSOY

I tried using Redirect permanent / https://www.mydomain.com/ but I was not successful. How do I use this for my web application? What you have provided is for a domain. I have an web application which will be running over the intranet
0
 
LVL 1

Author Comment

by:Vipin Kumar
ID: 40463620
@ Radek Baranowski

I have to ssh into a cisco router not a windows server. How do I pass on my commands to the router using ssh and then capture the output and display the same on web?
0
 
LVL 1

Accepted Solution

by:
Vipin Kumar earned 0 total points
ID: 40463633
@ Kerem ERSOY

I tried using the below code to redirect my webpage, but the webpage it is redirecting to https but the page is not opening what m I missing or is there any configuration that I need to in Apache to open a HTTPS page

<?php
if(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == ""){
    $redirect = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    header("Location: $redirect");
}
?>

Open in new window

0
 
LVL 1

Assisted Solution

by:Vipin Kumar
Vipin Kumar earned 0 total points
ID: 40463925
Below link contains the steps to configure the WAMP Server to accept SSL connection.

Step 1 - to configure wamp server to accept SSL connection

Then the next step specified by Kerem ERSOY needs to be implemented to redirect http to https. If one page needs to be redirected then implement the code on that page's beginning if all pages are to be redirected then it should be there on all the pages
0
 
LVL 11

Expert Comment

by:Radek Baranowski
ID: 40463972
http://php.net/manual/en/function.ssh2-exec.php

returns the stream of result data if command was successful
0
 
LVL 1

Author Closing Comment

by:Vipin Kumar
ID: 40471388
As no where it is mentioned that WAMP server also needs to be configured to accept SSL connection
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 …

718 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