Io non capisco, non riesco a far funzionare le sessioni e né i Cookie, qualcuno può aiutarmi?
Ci sono due file login.php:
Codice PHP:
session_start();
include 'config.php';
if(isset($_POST['log']))
{
$chat = 'originale';
if(isset($_POST['chat'])) $chat = $_POST['chat'];
$nome_u = mysql_real_escape_string($_POST['nick']);
$password = mysql_real_escape_string(md5($_POST['pass']));
switch($_POST['set'])
{
case 'reg':
$my_avatar = mysql_real_escape_string('http://media-cache-ec0.pinimg.com/236x/43/db/e7/43dbe7b1521057762f0144260cbf5a0d.jpg');
$my_ip = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
$my_power = 0;
$now_on_the_line = time();
$res_users = $DB->query("SELECT nome_u FROM users_bd_enchanted WHERE nome_u = '$nome_u'");
if($res_users->num_rows >= 1)
{
header("Location:main.php?ErrorReg=1");
}
else
{
$DB->query("INSERT INTO users_bd_enchanted (nome_u,passw_i,avatar_e,ip,date_reg,power,online_n) VALUES('$nome_u','$password','$my_avatar','$my_ip',now(),'0','$now_on_the_line')");
}
break;
case 'log':
if(isset($_POST['cookie'])) $cookiexists = true;
$res_users = $DB->query("SELECT * FROM users_bd_enchanted WHERE nome_u = '$nome_u' AND passw_i = '$password'");
if($res_users->num_rows == 0)
{
header("Location:main.php?ErrorLog=1");
exit();
}
else
{
$fetch_users = $res_users->fetch_assoc();
$my_id = $fetch_users['avatar_e'];
$my_avatar = $fetch_users['avatar_e'];
$my_ip = $fetch_users['ip'];
$my_power = $fetch_users['power'];
$now_on_the_line = time();
}
break;
}
if(isset($cookiexists))
{
$expire=time()+60*60*24*7;
setcookie('log',true,$expire);
setcookie('avatar',$my_avatar,$expire);
setcookie('nome',$nome_u,$expire);#,'/','lazytime.altervista.org', 1
setcookie('power',$my_power,$expire);
}
$_SESSION['log'] = true;
$_SESSION['nome'] = $nome_u;
$_SESSION['avatar'] = $my_avatar;
$_SESSION['power'] = $my_power;
$_SESSION['diz'] = 'normal';
switch($chat)
{
case 'Originale':header("Location:Sneh/");break;
case 'Rapida':header("Location:Sneh/handy/");break;
}
}
else
{
header("Location:main.php");
}
?>
e il file index.php:
Codice PHP:
session_start();
#se printo i cookie non si vede nulla se printo la sessione power o avatar v'è null