Skip to content
This repository was archived by the owner on Nov 21, 2019. It is now read-only.

Commit a828b8e

Browse files
committed
Fix for php_self ssl issue #18
1 parent 4bc0b8f commit a828b8e

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

lib/XeroOAuth.php

+27-20
Original file line numberDiff line numberDiff line change
@@ -562,27 +562,34 @@ function refreshToken($accessToken, $sessionHandle) {
562562
* whether to drop the querystring or not. Default true
563563
* @return string the current URL
564564
*/
565-
public static function php_self($dropqs = true) {
566-
$url = sprintf ( '%s://%s%s', empty ( $_SERVER ['HTTPS'] ) ? (@$_SERVER ['SERVER_PORT'] == '443' ? 'https' : 'http') : 'http', $_SERVER ['SERVER_NAME'], $_SERVER ['REQUEST_URI'] );
567-
568-
$parts = parse_url ( $url );
569-
570-
$port = $_SERVER ['SERVER_PORT'];
571-
$scheme = $parts ['scheme'];
572-
$host = $parts ['host'];
573-
$path = @$parts ['path'];
574-
$qs = @$parts ['query'];
575-
576-
$port or $port = ($scheme == 'https') ? '443' : '80';
577-
578-
if (($scheme == 'https' && $port != '443') || ($scheme == 'http' && $port != '80')) {
579-
$host = "$host:$port";
565+
public static function php_self($dropqs = true)
566+
{
567+
$protocol = 'http';
568+
if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on')
569+
{
570+
$protocol = 'https';
580571
}
581-
$url = "$scheme://$host$path";
582-
if (! $dropqs)
583-
return "{$url}?{$qs}";
584-
else
585-
return $url;
572+
elseif (isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] == '443'))
573+
{
574+
$protocol = 'https';
575+
}
576+
577+
$url = sprintf('%s://%s%s', $protocol, $_SERVER['SERVER_NAME'], $_SERVER['REQUEST_URI']);
578+
$parts = parse_url($url);
579+
$port = $_SERVER['SERVER_PORT'];
580+
$scheme = $parts['scheme'];
581+
$host = $parts['host'];
582+
$path = @$parts['path'];
583+
$qs = @$parts['query'];
584+
$port or $port = ($scheme == 'https') ? '443' : '80';
585+
if (($scheme == 'https' && $port != '443') || ($scheme == 'http' && $port != '80'))
586+
{
587+
$host = "$host:$port";
588+
}
589+
590+
$url = "$scheme://$host$path";
591+
if (!$dropqs) return "{$url}?{$qs}";
592+
else return $url;
586593
}
587594

588595
/*

0 commit comments

Comments
 (0)