Solved

Use HTTPS instead of HTTP in apache

Posted on 2014-11-24
10
222 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Imagine a situation that you have installed SSL (http://en.wikipedia.org/wiki/Secure_Sockets_Layer) Certificate on your Cisco ASA (Cisco Adaptive Security Appliance) firewall. Installation of SSL certificate on ASA is an another topic for which you …
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…
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 …

757 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

17 Experts available now in Live!

Get 1:1 Help Now