Salve a tutti, ho uno script per il login che una volta autenticato riesco a vedere del testo nascosto.
ecco la pagina dove dovrei loggarmi:
Codice PHP:
<?php
include_once("login/config.php");
include_once("login/auth.lib.php");
list($status, $user) = auth_get_status();
if($status == AUTH_LOGGED & auth_get_option("TRANSICTION METHOD") == AUTH_USE_LINK){
$link = "?uid=".$_GET['uid'];
}else $link = '';
?>
<?php
switch($status){
case AUTH_LOGGED:
?>
[b]Bentornato <?= $user["name"];?> [url="logout.php<?=$link?>"]Logout[/url][/b]</p>
<?php
break;
case AUTH_NOT_LOGGED:
?>
<form action="login.php<?=$link?>" method="post">
<input type="text" value="user" onclick="this.value=''" name="uname" />
<input type="password" value="123456" onclick="this.value=''" name="passw" />
<input class="submit" type="submit" value="login" />
</form>
<?php
break;
}
?>
login.php:
Codice PHP:
<?php
include_once("login/config.php");
include_once("login/auth.lib.php");
list($status, $user) = auth_get_status();
if($status == AUTH_NOT_LOGGED){
$uname = strtolower(trim($_POST['uname']));
$passw = strtolower(trim($_POST['passw']));
if($uname == "" or $passw == ""){
$status = AUTH_INVALID_PARAMS;
}else{
list($status, $user) = auth_login($uname, $passw);
if(!is_null($user)){
list($status, $uid) = auth_register_session($user);
}
}
}
switch($status){
case AUTH_LOGGED:
header("Refresh: 5;URL=index.php");
echo '<div align="center">Sei gia connesso ... attendi il reindirizzamento</div>';
break;
case AUTH_INVALID_PARAMS:
header("Refresh: 5;URL=index.php");
echo '<div align="center">Hai inserito dati non corretti ... attendi il reindirizzamento</div>';
break;
case AUTH_LOGEDD_IN:
switch(auth_get_option("TRANSICTION METHOD")){
case AUTH_USE_LINK:
header("Refresh: 5;URL=index.php?uid=".$uid);
break;
case AUTH_USE_COOKIE:
header("Refresh: 5;URL=index.php");
setcookie('uid', $uid, time()+3600*365);
break;
case AUTH_USE_SESSION:
header("Refresh: 5;URL=index.php");
$_SESSION['uid'] = $uid;
break;
}
echo '<div align="center">Ciao '.$user['name'].' ... attendi il reindirizzamento</div>';
break;
case AUTH_FAILED:
header("Refresh: 5;URL=index.php");
echo '<div align="center">Fallimento durante il tentativo di connessione ... attendi il reindirizzamento</div>';
break;
}
?>
config.php:
Codice PHP:
<?php
$_CONFIG['host'] = "62.149.150.177";
$_CONFIG['user'] = "Sql621441";
$_CONFIG['pass'] = "d6b55ed9";
$_CONFIG['dbname'] = "Sql621441_2";
$_CONFIG['table_sessioni'] = "sessioni";
$_CONFIG['table_utenti'] = "utenti";
$_CONFIG['expire'] = 60;
$_CONFIG['regexpire'] = 24; //in ore
$_CONFIG['check_table'] = array(
"username" => "check_username",
"password" => "check_global",
"name" => "check_global",
"surname" => "check_global",
"indirizzo" => "check_global",
"occupazione" => "check_global",
"mail" => "check_global"
);
function check_username($value){
global $_CONFIG;
$value = trim($value);
if($value == "")
return "Il campo non può essere lasciato vuoto";
$query = mysql_query("
SELECT id
FROM ".$_CONFIG['table_utenti']."
WHERE username='".$value."'");
if(mysql_num_rows($query) != 0)
return "Nome utente già utilizzato";
return true;
}
function check_global($value){
global $_CONFIG;
$value = trim($value);
if($value == "")
return "Il campo non può essere lasciato vuoto";
return true;
}
//--------------
define('AUTH_LOGGED', 99);
define('AUTH_NOT_LOGGED', 100);
define('AUTH_USE_COOKIE', 101);
define('AUTH_USE_LINK', 103);
define('AUTH_INVALID_PARAMS', 104);
define('AUTH_LOGEDD_IN', 105);
define('AUTH_FAILED', 106);
define('REG_ERRORS', 107);
define('REG_SUCCESS', 108);
define('REG_FAILED', 109);
$conn = mysql_connect($_CONFIG['host'], $_CONFIG['user'], $_CONFIG['pass']) or die('Impossibile stabilire una connessione');
mysql_select_db($_CONFIG['dbname']);
?>
auth.lib.php
Codice PHP:
function auth_login($uname, $passw){
global $_CONFIG;
$result = mysql_query("
SELECT *
FROM ".$_CONFIG['table_utenti']."
WHERE username='".$uname."' and password='".$passw."' and temp = '0'"
);
if(mysql_num_rows($result) != 1){
return array(AUTH_INVALID_PARAMS, NULL);
}else{
$data = mysql_fetch_array($result);
return array(AUTH_LOGEDD_IN, $data);
}
}
l'errore:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /web/htdocs/www.sefetna.com/home/login/auth.lib.php on line 95
riga 95:
if(mysql_num_rows($result) != 1){
a quanto ho capito non sta passando nessun valore, ma come mai?