?
Solved

PHP Undefined HTTPS index

Posted on 2011-10-16
4
Medium Priority
?
343 Views
Last Modified: 2013-12-12
I am trying to work my way through errors that appear in logs.

I have the following code checking to see if SSL is turned on, but get this error in my error log:
 Undefined index: HTTPS in /var/www/vhosts/xxx.org/httpdocs/Dev/Pal/d.php on line 10
(I've indicated line 10)

Is my syntax incorrect?
<?php
session_start();

// BRING IN COMMON CODE
require_once('ds-common.php');

print_r($_SESSION);
print_r($_POST);

line 10:if (strtolower($_SERVER['HTTPS']) != 'on')
{
      header("Location:  https://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']);
}

?>

Open in new window

0
Comment
Question by:kkbenj
  • 3
4 Comments
 
LVL 8

Expert Comment

by:Ahmed Merghani
ID: 36976575
Hi kkbenj,

Change

if (strtolower($_SERVER['HTTPS']) != 'on')

Open in new window


to

if (!empty($_SERVER['HTTPS']))

Open in new window

0
 
LVL 8

Accepted Solution

by:
Ahmed Merghani earned 2000 total points
ID: 36976578
Exactly you can use this:
if ( isset( $_SERVER["HTTPS"] ) && strtolower( $_SERVER["HTTPS"] ) == "on" )

Open in new window

0
 
LVL 8

Expert Comment

by:Ahmed Merghani
ID: 36976587
Sorry, use "!=" instead of "=="

if ( isset( $_SERVER["HTTPS"] ) && strtolower( $_SERVER["HTTPS"] ) != "on" )
0
 

Author Closing Comment

by:kkbenj
ID: 36976589
But I added the not's:

if ( !isset( $_SERVER["HTTPS"] ) && strtolower( $_SERVER["HTTPS"] ) != "on" ){
      header("Location:  https://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']);
}

Thank you.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to dynamically set the form action using jQuery.
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
Course of the Month13 days, 13 hours left to enroll

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