Solved

Use HTTPS instead of HTTP in apache

Posted on 2014-11-24
10
245 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
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 28

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
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

792 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