Problema - da Aruba ad Altervista
Problema - da Aruba ad Altervista postato il 28/12/2011 14:44:22 nel forum programmazione, open source e hosting
Buongiorno a tutti. Pochi giorni fa mi è stato chiesto di spostare un gdr su Altervista precedentemente collocato su Aruba. Vorrei che analizzaste insieme a me alcuni punti:
- carico i file su altervista con l'ausilio di filezilla
- modifico i parametri dei file password.php - open2.php
PASSWORD.PHP
$par_DbUser = 'ciao';
$par_DbPassword = 'password';
$par_Conn = 'my_ciao';
$par_DbHost = 'localhost';
OPEN2.PHP
$db_host = "localhost";
$db_user = "ciao";
$db_password = "password";
$db_name = "my_ciao";
- Importo il file sql: Tools - Importa Dump MySql.
A questo punto verifico che i parametri di connessione siano corretti e provo a visualizzare l'index; tutto scorre liscio a parte la segnalazione di due errori. La home è stata suddivisa in due form: uno ( laterale ) permette lo scorrere di news e l'altro non è che il re indirizzamento dei click effettuati su 'Login' e 'Registrazione'. Il form laterale segnala quest'errore:
Errore SQL !
SELECT COUNT(*) FROM Personaggio
No database selected
l'altro invece ..
Errore SQL !
SELECT Stato FROM Parametri WHERE Id = 2
No database selected
ho rivisto guide e segnalazioni di problemi da parte di altri utenti ma nulla. Cosa ne pensate ?
Pagine → 1
28/12/2011 17:43:16
La connessione al database non viene attivata. Teoricamente dovresti vedere anche gli avvisi che ti dicono che la password, l'utente o il nome del database sono errati. Ma dato che altervista disabilita tutti gli errori non ti viene detto.
Per correggere l'errore abilita gli tutti gli errori PHP usando la funzione error_reporting http://it.php.net/manual/en/function.error-reporting.php ↗, così vedrai gli errori completi che vengono visualizzati e protrai correggere cioè che ti viene indicato
28/12/2011 18:08:38 e modificato da dyrr il 28/12/2011 18:15:12
leoblacksoul ha scritto: La connessione al database non viene attivata. Teoricamente dovresti vedere anche gli avvisi che ti dicono che la password, l'utente o il nome del database sono errati. Ma dato che altervista disabilita tutti gli errori non ti viene detto.
Per correggere l'errore abilita gli tutti gli errori PHP usando la funzione error_reporting http://it.php.net/manual/en/function.error-reporting.php ↗, così vedrai gli errori completi che vengono visualizzati e protrai correggere cioè che ti viene indicato
Probabilmente non gli visualizza gli errori di username e password errati in quanto se non mi ricordo male, (o almeno quando lo usavo io altervista era cosi) su altervista non occorre che inserisci username e pass del database, li puoi lasciare anche vuoti, per cui lo script apre la connessione al database ma non seleziona il database giusto
Ora c'è da capire perchè non gli seleziona il database. nell'open2.php la funzione mysql_select_db() che variaible richiama tra le parentesi?
$par_Conn o $db_name
e nel caso richiami la prima nella pagina è stata inclusa la pagina contenente i dati di connesisone al db?
28/12/2011 18:30:22 e modificato da leoblacksoul il 28/12/2011 18:41:12
Quello è vero. Ma MySql genera un errore indipendentemente dal fatto che usi password o meno. Se non riesce a creare una connessione l'errore viene generato comunque. Abilitando gli errori a livello E_ALL, PHP dovrebbe mostrarti l'esatto motivo per cui non viene aperta una connessione.
Cioè, la morale è: dato che hai l'opportunità di vedere esattamente l'errore faglielo visualizzare, invece che procedere alla cieca
29/12/2011 02:40:52
OPEN2.PHP
mysql_select_db("my_ciao")
29/12/2011 02:58:24 e modificato da whatthehell il 29/12/2011 03:31:10
sono riuscito a risolvere il problema, anche se adesso me ne ripresenta un altro quando scrivo negli appositi form Nome e Password del personaggio per effettuare il login:
Fatal error: Call to undefined function: hash() in /membri/ciao/controlla.php on line 14
CONTROLLA.PHP
$_POST['pass'] = hash("whirlpool",$_POST['pass']);
credo di essere riuscito a raggirare il problema, sostituendo la stringa con:
ucfirst(mysql_real_escape_string($_POST['pass']));
Mi si ripresentano però altri errori quando tento di registrare il personaggio:
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /membri/ciao/phpmailer/class.phpmailer.php on line 53
CLASS.PHPMAILER.PHP
<?PHP
session_start();
#------------------------------------------------
# Librerie
#------------------------------------------------
include('inc/open2.php');
#------------------------------------------------
# Extrapolazione codice sql dopo securizzazione
#------------------------------------------------
if (isset($_POST['login']) && isset($_POST['pass']))
{
$_POST['login'] = ucfirst(mysql_real_escape_string($_POST['login']));
$_POST['pass'] = hash("whirlpool",$_POST['pass']);;
}
#------------------------------------------------
# Download dall'sql dati PG
#------------------------------------------------
$query = 'SELECT Nome,Cognome,Pass,IDRazza,IDGilda,IDOrg,Sesso,Email,Master,Soldi,Super,Admin,Dispo,parametro FROM Personaggio WHERE Nome="'.$_POST['login'].'" AND Pass="'.$_POST['pass'].'"';
$result = mysql_query($query) or die('Errore SQL !<br>'.$query.'<br>'.mysql_error());
$rowVerif = mysql_fetch_array($result);
#----------------------------------------------------
# Verifica corrispondenza e stockaggio sessioni
#----------------------------------------------------
if ($rowVerif['Nome'] == $_POST['login'] && $rowVerif['Pass'] == $_POST['pass'])
{
$_SESSION['AUTH'] = 1;
$_SESSION['Login'] = $rowVerif['Nome'];
$_SESSION['cognome'] = $rowVerif['Cognome'];
$_SESSION['idrazza'] = $rowVerif['IDRazza'];
$_SESSION['idgilda'] = $rowVerif['IDGilda'];
$_SESSION['idorg'] = $rowVerif['IDOrg'];
$_SESSION['sesso'] = $rowVerif['Sesso'];
$_SESSION['email'] = $rowVerif['Email'];
$_SESSION['Master'] = $rowVerif['Master'];
$_SESSION['soldi'] = $rowVerif['Soldi'];
$_SESSION['Super'] = $rowVerif['Super'];
$_SESSION['Admin'] = $rowVerif['Admin'];
$_SESSION['dispo'] = $rowVerif['Dispo'];
$_SESSION['Stanza'] = "1";
if ( ($rowVerif['IDRazza'] % 1000 == 0) && ($rowVerif['IDRazza'] != 2000) && ($rowVerif['IDRazza'] != 4000) ) { $_SESSION['caporazza'] = 1; } else { $_SESSION['caporazza'] = 0; }
if ( ($rowVerif['IDGilda'] % 100 == 0) && ($rowVerif['IDGilda'] != 0) && ($rowVerif['IDGilda'] != 1) ) { $_SESSION['capogilda'] = 1; } else { $_SESSION['capogilda'] = 0; }
if ( ($rowVerif['IDOrg'] % 100 == 0) && ($rowVerif['IDOrg'] != 0) ) { $_SESSION['capomestiere'] = 1; } else { $_SESSION['capomestiere'] = 0; }
#--------------------------------------------------------------
# Controllo i punti fama, se sono 50 gli do la carica di Cittadino
#--------------------------------------------------------------
if ( $rowVerif['parametro'] >= 50 && $rowVerif['IDOrg'] == 0) {
$sql = "UPDATE Personaggio SET IDOrg=1 WHERE Nome = '$_SESSION[Login]'";
mysql_query($sql) or die('Errore SQL !<br>'.$sql.'<br>'.mysql_error());
$_SESSION['idorg'] = 1;
}
#--------------------------------------------------------------
# Controllo Doppio.
#--------------------------------------------------------------
$host = gethostbyaddr($_SERVER["REMOTE_ADDR"]);
$sql = "SELECT * FROM LogEntrate WHERE (IP = '$_SERVER[REMOTE_ADDR]' OR Host = '$host') AND Nome != '$rowVerif[Nome]' ";
$query = mysql_query($sql) or die('Errore SQL !<br>'.$sql.'<br>'.mysql_error());
while ($res = mysql_fetch_array($query)) {
$doppio = $res['Nome'];
$nome = $rowVerif['Nome'];
$sql = "INSERT INTO LogDoppi (Nome,Doppio,DataEvento,IP,Host) VALUES ('$nome','$doppio',NOW(),'$_SERVER[REMOTE_ADDR]','$host')";
mysql_query($sql) or die('Errore SQL !<br>'.$sql.'<br>'.mysql_error());
}
#--------------------------------------------------------------
# Messa in Online e accesso alla citta'.
#--------------------------------------------------------------
$sql = "SELECT Nome FROM Presenti WHERE Nome='$_SESSION[Login]'";
$req = mysql_query($sql) or die('Errore SQL !<br>'.$sql.'<br>'.mysql_error());
$numOnline = mysql_num_rows($req);
if ($numOnline == 0)
{
// Scarico i dati di Razza e li metto in variabile.
$sql = "SELECT Razza,URLImg FROM Razza WHERE IDRazza = '$_SESSION[idrazza]'";
$req = mysql_query($sql) or die('Errore SQL !<br>'.$sql.'<br>'.mysql_error());
$razza = mysql_fetch_assoc($req);
$_SESSION['NomeRazza'] = $razza['Razza'];
$_SESSION['URLImgRazza'] = $razza['URLImg'];
// Scarico i dati di Gilda e li metto in variabile.
$sql = "SELECT Gilda,URLImg FROM Gilda WHERE IDGilda = '$_SESSION[idgilda]'";
$req = mysql_query($sql) or die('Errore SQL !<br>'.$sql.'<br>'.mysql_error());
$gilda = mysql_fetch_assoc($req);
$_SESSION['NomeGilda'] = $gilda['Gilda'];
$_SESSION['URLImgGilda'] = $gilda['URLImg'];
// Scarico i dati di Mestiere (org) e li metto in variabile.
$sql = "SELECT Organizzazione,URLImg FROM Organizzazione WHERE IDOrg = '$_SESSION[idorg]'";
$req = mysql_query($sql) or die('Errore SQL !<br>'.$sql.'<br>'.mysql_error());
$org = mysql_fetch_assoc($req);
$_SESSION['NomeOrganizzazione'] = $org['Organizzazione'];
$_SESSION['URLImgOrganizzazione'] = $org['URLImg'];
// Butto tutto nella tabella degli Online & nella tabella LogEntrate
$sql = "INSERT into Presenti (Nome,OraEntrata,Stanza,StanzaApparente,UltimoRefresh,Pres,IDRazza,DescRazza,ImgRazza,Master,Sesso,IDGilda,DescGilda,ImgGilda,LastIP,IDMest,DescMest,ImgMest) values ('$_SESSION[Login]',NOW(),'1','1',NOW(),'','$_SESSION[idrazza]','$razza[Razza]','$razza[URLImg]','$_SESSION[Master]','$_SESSION[sesso]','$_SESSION[idgilda]','$gilda[Gilda]','$gilda[URLImg]','$_SERVER[REMOTE_ADDR]','$_SESSION[idorg]','$org[Organizzazione]','$org[URLImg]')";
mysql_query($sql) or die('Errore SQL !<br>'.$sql.'<br>'.mysql_error());
$host = gethostbyaddr($_SERVER["REMOTE_ADDR"]);
$sql = "INSERT INTO LogEntrate (Nome,DataEvento,IP,Host) VALUES ('$_SESSION[Login]',NOW(),'$_SERVER[REMOTE_ADDR]','$host')";
mysql_query($sql) or die('Errore SQL !<br>'.$sql.'<br>'.mysql_error());
$sql = "UPDATE Personaggio SET avvistato=NOW() WHERE Nome = '$_SESSION[Login]'";
mysql_query($sql) or die('Errore SQL !<br>'.$sql.'<br>'.mysql_error());
print '<META http-equiv="refresh" content="1;URL=main.php" target="_top">';
print '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Whispering Mists</title>
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet" type="text/css" href="stile.css" media="screen" />
</head>
<body style="background-color:transparent;">
<table class="testo">
<tr>
<td>Accesso in corso, attendere...</td>
</tr>
</table>';
}
else if ($numOnline == 1)
{// Scarico i dati di Razza e li metto in variabile.
$sql = "SELECT Razza,URLImg FROM Razza WHERE IDRazza = '$_SESSION[idrazza]'";
$req = mysql_query($sql) or die('Errore SQL !<br>'.$sql.'<br>'.mysql_error());
$razza = mysql_fetch_assoc($req);
$_SESSION['NomeRazza'] = $razza['Razza'];
$_SESSION['URLImgRazza'] = $razza['URLImg'];
// Scarico i dati di Gilda e li metto in variabile.
$sql = "SELECT Gilda,URLImg FROM Gilda WHERE IDGilda = '$_SESSION[idgilda]'";
$req = mysql_query($sql) or die('Errore SQL !<br>'.$sql.'<br>'.mysql_error());
$gilda = mysql_fetch_assoc($req);
$_SESSION['NomeGilda'] = $gilda['Gilda'];
$_SESSION['URLImgGilda'] = $gilda['URLImg'];
// Scarico i dati di Mestiere (org) e li metto in variabile.
$sql = "SELECT Organizzazione,URLImg FROM Organizzazione WHERE IDOrg = '$_SESSION[idorg]'";
$req = mysql_query($sql) or die('Errore SQL !<br>'.$sql.'<br>'.mysql_error());
$org = mysql_fetch_assoc($req);
$_SESSION['NomeOrganizzazione'] = $org['Organizzazione'];
$_SESSION['URLImgOrganizzazione'] = $org['URLImg'];
// Butto tutto nella tabella degli Online
$sql = "UPDATE Presenti SET Nome='$_SESSION[Login]',OraEntrata=NOW(),Stanza='1',StanzaApparente='1',UltimoRefresh=NOW(),Pres='',IDRazza='$_SESSION[idrazza]',DescRazza='$razza[Razza]',ImgRazza='$razza[URLImg]',Master='$_SESSION[Master]',Sesso='$_SESSION[sesso]',IDGilda='$_SESSION[idgilda]',DescGilda='$gilda[Gilda]',ImgGilda='$gilda[URLImg]',LastIP='$_SERVER[REMOTE_ADDR]',IDMest='$_SESSION[idorg]',DescMest='$org[Organizzazione]',ImgMest='$org[URLImg]' WHERE Nome='$_SESSION[Login]'";
mysql_query($sql) or die('Errore SQL !<br>'.$sql.'<br>'.mysql_error());
$host = gethostbyaddr($_SERVER["REMOTE_ADDR"]);
$sql = "INSERT INTO LogEntrate (Nome,DataEvento,IP,Host) VALUES ('$_SESSION[Login]',NOW(),'$_SERVER[REMOTE_ADDR]','$host')";
mysql_query($sql) or die('Errore SQL !<br>'.$sql.'<br>'.mysql_error());
$sql = "UPDATE Personaggio SET avvistato=NOW() WHERE Nome = '$_SESSION[Login]'";
mysql_query($sql) or die('Errore SQL !<br>'.$sql.'<br>'.mysql_error());
print '<META http-equiv="refresh" content="1;URL=main.php" target="_top">';
print '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Whispering Mists</title>
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet" type="text/css" href="stile.css" media="screen" />
</head>
<body style="background-color:transparent;">
<table class="testo">
<tr>
<td>Accesso in corso, attendere...</td>
</tr>
</table>';
}
}
else { ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Whispering Mists</title>
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet" type="text/css" href="stile.css" media="screen" />
</head>
<body style="background-color:transparent;">
<table class="testo">
<tr>
<td>Login o Password errati.</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td onClick="top.frames['contents'].location.href='login.php'"><input type="submit" value="Riprova" class="input" name="submit"></td>
</tr>
</table>
</body>
</html>
<?PHP } ?>
Discussione seguita da
Pagine → 1
Rispondi alla Discussione Segui Discussione Inoltra Discussione Forum Programmazione, Open Source e Hosting Elenco Forum
Articoli, Interviste e altre Risorse!
New Orleans ↗
Storie di Agarthi ↗
Tibia ↗
The Coven ↗
Fallen Gods ↗
Seconda Era ↗