?
Solved

Use HTTPS instead of HTTP in apache

Posted on 2014-11-24
10
Medium Priority
?
356 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 12

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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 12

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …
Suggested Courses

616 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