?
avatar tompap
tompap
17 Aug 2015

Steps to reproduce the issue

Create a CLI step, with a echo JURI::base() in it.
Run it

Expected result

No Notice

Actual result

PHP Notice: Undefined index: HTTP_HOST in /home/www/clients/client1/web24/web/products/libraries/joomla/uri/uri.php on line 96
Notice: Undefined index: HTTP_HOST in /home/www/clients/client1/web24/web/products/libraries/joomla/uri/uri.php on line 96

System information (as much as possible)

Please note that, to be able to use JURI you need to set a live_site variable in configuration.php otherwise URI is empty.

Additional comments

A possible fix is to add some if (isset) under line 96 in uri.php
$theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'];

Votes

# of Users Experiencing Issue
0/1
Average Importance Score
1.00

avatar tompap tompap - open - 17 Aug 2015
avatar vess
vess - comment - 19 Aug 2015

A possible fix is to add some if (isset) under line 96 in uri.php

No, it's not! Normally your script would not even execute these lines (87 to 103) because you're not running IIS on your Linux host! It does only execute these lines because REQUEST_URI (line 81) is not set in $_SERVER array when you run your cli app. And since HTTP_HOST is also not set you got this notice.
And because there isn't a uri request in a cli app, using JUri::base() makes not much sense I would say.

avatar tompap
tompap - comment - 22 Aug 2015

Hello,

Jus take the case of a cron task, than check for expiration of something and must send email with links inside, you need to know the URL of your website. So it make sense to use JURI::base()
(in this case you need to have live_site in configuration set to something)

This is working great today, JURI::base() returns URL if (live_site is set) , only a PHP Notice.

We have an isset on $_SERVER['REQUEST_URI'] why not add an isset on $_SERVER['HTTP_HOST'],
this code could be executed on Linux CLI (no check to prevent it) so added a isset (willl check if we are on IIS or not and only perform the code if IIS)

avatar fastslack
fastslack - comment - 22 Aug 2015

I had this issue before, just add this line on your __constructor()

        // Prevent Joomla! libraries error
        // PHP Notice:  Undefined index: HTTP_HOST
        $_SERVER['HTTP_HOST'] = null;   
avatar vess
vess - comment - 23 Aug 2015

Jus take the case of a cron task, than check for expiration of something and must send email with links inside, you need to know the URL of your website. So it make sense to use JURI::base()
(in this case you need to have live_site in configuration set to something)

And again, no it makes no sense to use JUri::base() in this case... because it will return the live_site variable...

We have an isset on $_SERVER['REQUEST_URI'] why not add an isset on $_SERVER['HTTP_HOST'],
this code could be executed on Linux CLI (no check to prevent it) so added a isset (willl check if we are on IIS or not and only perform the code if IIS)

If we on IIS or not is already checked, as I mentioned... the ckeck for REQUEST_URI is there because it is the check since IIS does not use REQUEST_URI...
JUri::base() is for request calls, and you don't have a request call in a cli app!

avatar fastslack
fastslack - comment - 23 Aug 2015
avatar tompap
tompap - comment - 24 Aug 2015

And again, no it makes no sense to use JUri::base() in this case... because it will return the live_site variable...

==> It's exactly what I want I want JURI::base() to return live_site if using CLI.
I cannot used directly live_site in my CLI code (because the same code can also be executed from an URL, so I must use JURI::base().

Anyway, in anycase testing a variable before using it, it's not a bad thing !
We are just talking about removing a PHP Notice.

@fastslack , your fix is not working because
public static function base($pathonly = false)
{
....
$uri = self::getInstance();

And public static function getInstance($uri = 'SERVER')
{
So URI = SERVER even if CLI application

I still think something like this will be better :

f (!empty($_SERVER['PHP_SELF']) && !empty($_SERVER['REQUEST_URI']))
{
...
}
else if (!empty($_SERVER['HTTP_HOST']) && !empty($_SERVER['SCRIPT_NAME']))
{

} else {
$theURI = $config->get('live_site');
}

avatar vess
vess - comment - 25 Aug 2015

I cannot used directly live_site in my CLI code (because the same code can also be executed from an URL, so I must use JURI::base().

Yes you can, since the only difference would be the addition of "/administrator" to the path if your url call is from the backend and that you can handle within your code.
You both want to fix code what doesn't need a fix, instead you should fix your code!

avatar brianteeman
brianteeman - comment - 6 Apr 2016

Closing as not a core issue


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/7716.

avatar brianteeman brianteeman - change - 6 Apr 2016
Status New Closed
Closed_Date 0000-00-00 00:00:00 2016-04-06 11:21:37
Closed_By brianteeman
avatar brianteeman brianteeman - close - 6 Apr 2016

Add a Comment

Login with GitHub to post a comment