PHP Notice: Undefined index: HTTP_HOST

Postate qui per tutte le discussioni legate a Linux in generale.

Moderatore: Staff

Regole del forum
1) Citare sempre la versione di Slackware usata, la versione del Kernel e magari anche la versione della libreria coinvolta. Questi dati aiutano le persone che possono rispondere.
2) Per evitare confusione prego inserire in questo forum solo topic che riguardano appunto Gnu/Linux in genere, se l'argomento è specifico alla Slackware usate uno dei forum Slackware o Slackware64.
3) Leggere attentamente le risposte ricevute
4) Scrivere i messaggi con il colore di default, evitare altri colori.
5) Scrivere in Italiano o in Inglese, se possibile grammaticalmente corretto, evitate stili di scrittura poco chiari, quindi nessuna abbreviazione tipo telegramma o scrittura stile SMS o CHAT.
6) Appena registrati è consigliato presentarsi nel forum dedicato.

La non osservanza delle regole porta a provvedimenti di vari tipo da parte dello staff, in particolare la non osservanza della regola 5 porta alla cancellazione del post e alla segnalazione dell'utente. In caso di recidività l'utente rischia il ban temporaneo.
Rispondi
Avatar utente
Loris
Admin
Admin
Messaggi: 7731
Iscritto il: lun 31 mar 2003, 0:00
Nome Cognome: Loris Vincenzi
Località: Gradisca D'Isonzo
Contatta:

PHP Notice: Undefined index: HTTP_HOST

Messaggio da Loris »

Voglio sistemare questo errore che ci troviamo nei log.

Codice: Seleziona tutto

[Wed Dec 12 22:15:39 2007] [error] [client ::1] PHP Notice:  Undefined index:  HTTP_HOST in index.php on line 28
Di seguito la porzione di codice incriminato, la freccia indica la linea 28

Codice: Seleziona tutto

/ SSL check - $http_host returns <live site url>:<port number if it is 443>
==> $http_host = explode(':', $_SERVER['HTTP_HOST'] );
if( (!empty( $_SERVER['HTTPS'] ) && strtolower( $_SERVER['HTTPS'] ) != 'off' || isset( $http_host[1] ) && $http_host[1] == 443) && substr( $mosConfig_live_site, 0, 8 ) != 'https://' ) {
	$mosConfig_live_site = 'https://'.substr( $mosConfig_live_site, 7 );
Ricordo che la versione di php installata è la 5.2.5
"Ho una testa piuttosto balzana e comunque non sono quello che credete" - Roger Keith Barrett

Avatar utente
JohnnyMnemonic
Staff
Staff
Messaggi: 2733
Iscritto il: dom 5 set 2004, 0:00
Nome Cognome: Giuseppe Palmiotto
Slackware: 14.0
Kernel: 3.5.5-thanatos
Località: Bologna
Contatta:

Messaggio da JohnnyMnemonic »

Cos'è HTTP_HOST ? Una costante creata con define oppure una variabile?
Nel secondo caso ci andrebbe $ davanti.

Avatar utente
Loris
Admin
Admin
Messaggi: 7731
Iscritto il: lun 31 mar 2003, 0:00
Nome Cognome: Loris Vincenzi
Località: Gradisca D'Isonzo
Contatta:

Messaggio da Loris »

Non vedo nessun define, ma considera che non ci capisco tanto di ste cose, in ogni caso ho provato a mettere il $ ma ottengo lo stesso errore. Cosa ti serve per capire meglio l'errore ?
Se vuoi posso linkare l'index.php
"Ho una testa piuttosto balzana e comunque non sono quello che credete" - Roger Keith Barrett

jaro
Linux 0.x
Linux 0.x
Messaggi: 7
Iscritto il: lun 14 mar 2005, 0:00

Messaggio da jaro »

Ciao Loris,

percaso la porta 443 (https) è chiusa?

in quella porzione di codice viene testato in tutti i modi se la richiesta viene fatta sulla porta 443, può darsi che uno dei test che vengono eseguiti produca un errore in assenza di argomenti da confrontare... la butto li

scommetto che con le versioni precedenti di joomla non avveniva.

se non usi la porta 443, controlla che nel codice a seguire venga valorizzata la variabile
$mosConfig_live_site
e commenta tutto l'if

se vuoi puoi monitorare facendo l'echo delle variabili e poi vedi.

ti rispondo a naso cioè non ho fatto nessuna prova ma...
ciao

Avatar utente
Loris
Admin
Admin
Messaggi: 7731
Iscritto il: lun 31 mar 2003, 0:00
Nome Cognome: Loris Vincenzi
Località: Gradisca D'Isonzo
Contatta:

Messaggio da Loris »

La 443 è chiusa, ho provato a commentare l'if ma quando carico la pagina diventa bianca.
Questo è l'index.php di joomla

Codice: Seleziona tutto

<?php
/**
* @version $Id: index.php 6022 2006-12-18 22:30:07Z friesengeist $
* @package Joomla
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// Set flag that this is a parent file
define( '_VALID_MOS', 1 );

// checks for configuration file, if none found loads installation page
if (!file_exists( 'configuration.php' ) || filesize( 'configuration.php' ) < 10) {
	$self = rtrim( dirname( $_SERVER['PHP_SELF'] ), '/\\' ) . '/';
	header("Location: http://" . $_SERVER['HTTP_HOST'] . $self . "installation/index.php" );
	exit();
}

require( 'globals.php' );
require_once( 'configuration.php' );

// SSL check - $http_host returns <live site url>:<port number if it is 443>
$http_host = explode(':', $_SERVER['HTTP_HOST'] );
if( (!empty( $_SERVER['HTTPS'] ) && strtolower( $_SERVER['HTTPS'] ) != 'off' || isset( $http_host[1] ) && $http_host[1] == 443) && substr( $mosConfig_live_site, 0, 8 ) != 'https://' ) {
	$mosConfig_live_site = 'https://'.substr( $mosConfig_live_site, 7 );
}

require_once( 'includes/joomla.php' );

//Installation sub folder check, removed for work with SVN
if (file_exists( 'installation/index.php' ) && $_VERSION->SVN == 0) {
	define( '_INSTALL_CHECK', 1 );
	include ( $mosConfig_absolute_path .'/offline.php');
	exit();
}

// displays offline/maintanance page or bar
if ($mosConfig_offline == 1) {
	require( $mosConfig_absolute_path .'/offline.php' );
}

// load system bot group
$_MAMBOTS->loadBotGroup( 'system' );

// trigger the onStart events
$_MAMBOTS->trigger( 'onStart' );

if (file_exists( $mosConfig_absolute_path .'/components/com_sef/sef.php' )) {
	require_once( $mosConfig_absolute_path .'/components/com_sef/sef.php' );
} else {
	require_once( $mosConfig_absolute_path .'/includes/sef.php' );
}
require_once( $mosConfig_absolute_path .'/includes/frontend.php' );

// retrieve some expected url (or form) arguments
$option = strval( strtolower( mosGetParam( $_REQUEST, 'option' ) ) );
$Itemid = intval( mosGetParam( $_REQUEST, 'Itemid', null ) );

if ($option == '') {
	if ($Itemid) {
		$query = "SELECT id, link"
		. "\n FROM #__menu"
		. "\n WHERE menutype = 'mainmenu'"
		. "\n AND id = " . (int) $Itemid
		. "\n AND published = 1"
		;
		$database->setQuery( $query );
	} else {
		$query = "SELECT id, link"
		. "\n FROM #__menu"
		. "\n WHERE menutype = 'mainmenu'"
		. "\n AND published = 1"
		. "\n ORDER BY parent, ordering"
		;
		$database->setQuery( $query, 0, 1 );
	}
	$menu = new mosMenu( $database );
	if ($database->loadObject( $menu )) {
		$Itemid = $menu->id;
	}
	$link = $menu->link;
	if (($pos = strpos( $link, '?' )) !== false) {
		$link = substr( $link, $pos+1 ). '&Itemid='.$Itemid;
	}
	parse_str( $link, $temp );
	/** this is a patch, need to rework when globals are handled better */
	foreach ($temp as $k=>$v) {
		$GLOBALS[$k] = $v;
		$_REQUEST[$k] = $v;
		if ($k == 'option') {
			$option = $v;
		}
	}
}
if ( !$Itemid ) {
// when no Itemid give a default value
	$Itemid = 99999999;
}

// mainframe is an API workhorse, lots of 'core' interaction routines
$mainframe = new mosMainFrame( $database, $option, '.' );
$mainframe->initSession();

// trigger the onAfterStart events
$_MAMBOTS->trigger( 'onAfterStart' );

// checking if we can find the Itemid thru the content
if ( $option == 'com_content' && $Itemid === 0 ) {
	$id 	= intval( mosGetParam( $_REQUEST, 'id', 0 ) );
	$Itemid = $mainframe->getItemid( $id );
}

/** do we have a valid Itemid yet?? */
if ( $Itemid === 0 ) {
	/** Nope, just use the homepage then. */
	$query = "SELECT id"
	. "\n FROM #__menu"
	. "\n WHERE menutype = 'mainmenu'"
	. "\n AND published = 1"
	. "\n ORDER BY parent, ordering"
	;
	$database->setQuery( $query, 0, 1 );
	$Itemid = $database->loadResult();
}

// patch to lessen the impact on templates
if ($option == 'search') {
	$option = 'com_search';
}

// loads english language file by default
if ($mosConfig_lang=='') {
	$mosConfig_lang = 'english';
}
include_once( $mosConfig_absolute_path .'/language/' . $mosConfig_lang . '.php' );

// frontend login & logout controls
$return 	= strval( mosGetParam( $_REQUEST, 'return', NULL ) );
$message 	= intval( mosGetParam( $_POST, 'message', 0 ) );
if ($option == 'login') {
	$mainframe->login();

	// JS Popup message
	if ( $message ) {
		?>
		<script language="javascript" type="text/javascript">
		<!--//
		alert( "<?php echo addslashes( _LOGIN_SUCCESS ); ?>" );
		//-->
		</script>
		<?php
	}

	if ( $return && !( strpos( $return, 'com_registration' ) || strpos( $return, 'com_login' ) ) ) {
	// checks for the presence of a return url
	// and ensures that this url is not the registration or login pages
		// If a sessioncookie exists, redirect to the given page. Otherwise, take an extra round for a cookiecheck
		if (isset( $_COOKIE[mosMainFrame::sessionCookieName()] )) {
			mosRedirect( $return );
		} else {
			mosRedirect( $mosConfig_live_site .'/index.php?option=cookiecheck&return=' . urlencode( $return ) );
		}
	} else {
		// If a sessioncookie exists, redirect to the start page. Otherwise, take an extra round for a cookiecheck
		if (isset( $_COOKIE[mosMainFrame::sessionCookieName()] )) {
			mosRedirect( $mosConfig_live_site .'/index.php' );
		} else {
			mosRedirect( $mosConfig_live_site .'/index.php?option=cookiecheck&return=' . urlencode( $mosConfig_live_site .'/index.php' ) );
		}
	}

} else if ($option == 'logout') {
	$mainframe->logout();

	// JS Popup message
	if ( $message ) {
		?>
		<script language="javascript" type="text/javascript">
		<!--//
		alert( "<?php echo addslashes( _LOGOUT_SUCCESS ); ?>" );
		//-->
		</script>
		<?php
	}

	if ( $return && !( strpos( $return, 'com_registration' ) || strpos( $return, 'com_login' ) ) ) {
	// checks for the presence of a return url
	// and ensures that this url is not the registration or logout pages
		mosRedirect( $return );
	} else {
		mosRedirect( $mosConfig_live_site.'/index.php' );
	}
} else if ($option == 'cookiecheck') {
	// No cookie was set upon login. If it is set now, redirect to the given page. Otherwise, show error message.
	if (isset( $_COOKIE[mosMainFrame::sessionCookieName()] )) {
		mosRedirect( $return );
	} else {
		mosErrorAlert( _ALERT_ENABLED );
	}
}

/** get the information about the current user from the sessions table */
$my = $mainframe->getUser();

// detect first visit
$mainframe->detect();

// set for overlib check
$mainframe->set( 'loadOverlib', false );

$gid = intval( $my->gid );

// gets template for page
$cur_template = $mainframe->getTemplate();
/** temp fix - this feature is currently disabled */

/** @global A places to store information from processing of the component */
$_MOS_OPTION = array();

// precapture the output of the component
require_once( $mosConfig_absolute_path . '/editor/editor.php' );

ob_start();

if ($path = $mainframe->getPath( 'front' )) {
	$task 	= strval( mosGetParam( $_REQUEST, 'task', '' ) );
	$ret 	= mosMenuCheck( $Itemid, $option, $task, $gid );

	if ($ret) {
		require_once( $path );
	} else {
		mosNotAuth();
	}
} else {
	header( 'HTTP/1.0 404 Not Found' );
	echo _NOT_EXIST;
}

$_MOS_OPTION['buffer'] = ob_get_contents();

ob_end_clean();

initGzip();

header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
header( 'Cache-Control: no-store, no-cache, must-revalidate' );
header( 'Cache-Control: post-check=0, pre-check=0', false );
header( 'Pragma: no-cache' );

// display the offline alert if an admin is logged in
if (defined( '_ADMIN_OFFLINE' )) {
	include( $mosConfig_absolute_path .'/offlinebar.php' );
}

// loads template file
if ( !file_exists( $mosConfig_absolute_path .'/templates/'. $cur_template .'/index.php' ) ) {
	echo _TEMPLATE_WARN . $cur_template;
} else {
	require_once( $mosConfig_absolute_path .'/templates/'. $cur_template .'/index.php' );
	echo '<!-- '. time() .' -->';
}

// displays queries performed for page
if ($mosConfig_debug) {
	echo $database->_ticker . ' queries executed';
	echo '<pre>';
 	foreach ($database->_log as $k=>$sql) {
 		echo $k+1 . "\n" . $sql . '<hr />';
	}
	echo '</pre>';
}

doGzip();
?>
Come lo modifico ?
"Ho una testa piuttosto balzana e comunque non sono quello che credete" - Roger Keith Barrett

Avatar utente
targzeta
Iper Master
Iper Master
Messaggi: 6643
Iscritto il: gio 3 nov 2005, 14:05
Nome Cognome: Emanuele Tomasi
Slackware: 64-current
Kernel: latest stable
Desktop: IceWM
Località: Carpignano Sal. (LE) <-> Pisa

Messaggio da targzeta »

Il punto è che il contenuto di:

Codice: Seleziona tutto

$_SERVER['HTTP_HOST']
altro non è che il contenuto del campo "Header" della richiesta http. Dato che è nella richiesta, vuol dire che il browser dell'utente dovrebbe specificare questo header, ma non tutti i browser lo fanno. Indi per cui, con questi browser, il campo "Header" non esiste e quindi tenti di accedere ad una locazione dell'array $_SERVER non esistente.

Noto il problema, nota la soluzione ;). Dovrebbe bastare modificare l'index.php da te postato come segue (stampo solo le righe interessate):

Codice: Seleziona tutto

if ( array_key_exists('HTTP_HOST',$_SERVER) )
  {
     // SSL check - $http_host returns <live site url>:<port number if it is 443>
    $http_host = explode(':', $_SERVER['HTTP_HOST'] );
    if( (!empty( $_SERVER['HTTPS'] ) && strtolower( $_SERVER['HTTPS'] ) != 'off' || isset( $http_host[1] ) && $http_host[1] == 443) 
        && substr($mosConfig_live_site, 0, 8 ) != 'https://' ) 
      { 
        $mosConfig_live_site = 'https://'.substr( $mosConfig_live_site, 7 );
      }
  }
In pratica, prima che venga usata, si controlla che effettivamente esista nell'array $_SERVER la locazione 'HTTP_HOST', cosa che è buona regola fare sempre!!! Ma evidentemente quelli di joomla....

C'è da dire però che questo controllino andrebbe fatto per tutti gli script che usano la variabile $_SERVER in quel modo (nota che anche più su nello stesso script viene usata). Ma per ora, considerato che è solo lì che ti viene notificato, dovrebbe voler dire che basta così :).

Spina
Se pensi di essere troppo piccolo per fare la differenza, prova a dormire con una zanzara -- Dalai Lama

jaro
Linux 0.x
Linux 0.x
Messaggi: 7
Iscritto il: lun 14 mar 2005, 0:00

Messaggio da jaro »

quoto in toto

Avatar utente
Loris
Admin
Admin
Messaggi: 7731
Iscritto il: lun 31 mar 2003, 0:00
Nome Cognome: Loris Vincenzi
Località: Gradisca D'Isonzo
Contatta:

Messaggio da Loris »

Funziona 8)
Spina, Loris e il log di Slacky.eu ringraziano :D
"Ho una testa piuttosto balzana e comunque non sono quello che credete" - Roger Keith Barrett

Avatar utente
nuitari
Linux 3.x
Linux 3.x
Messaggi: 777
Iscritto il: dom 14 ott 2007, 12:51
Slackware: 12.0
Località: San Colombano al Lambro
Contatta:

Messaggio da nuitari »

Il vero problema è che stai usando Joomla 8)

Avatar utente
Loris
Admin
Admin
Messaggi: 7731
Iscritto il: lun 31 mar 2003, 0:00
Nome Cognome: Loris Vincenzi
Località: Gradisca D'Isonzo
Contatta:

Messaggio da Loris »

nuitari ha scritto:Il vero problema è che stai usando Joomla 8)
E fammi sto portalone ;)
"Ho una testa piuttosto balzana e comunque non sono quello che credete" - Roger Keith Barrett

Avatar utente
nuitari
Linux 3.x
Linux 3.x
Messaggi: 777
Iscritto il: dom 14 ott 2007, 12:51
Slackware: 12.0
Località: San Colombano al Lambro
Contatta:

Messaggio da nuitari »

Te lo faccio davvero.
Se mi contatti su MSN ne parliamo.

Rispondi