Salve, ho questo autologin che mi stampa i dati solo se faccio "autologin".
Mi dite come mai?
questo è i login.php
questo è il check che sta nelle pagine riservate:
e questo è l'area riservata:
Mi sapete dire come fare prenderli tutte due sia sessioni/cookie nello solito tempo.
Grazie mille.
Per favore uno che mi aiuti.
Grazie.
Mi dite come mai?
questo è i login.php
PHP:
<?php
session_start();
require_once(dirname(__FILE__) . '/../inc.php');
if(isset($_POST['Login']))
{
if($_POST['username']!='' && $_POST['password']!='')
{
$query = mysql_query('SELECT * FROM users WHERE Username = "'.mysql_real_escape_string($_POST['username']).'" AND Password = "'.mysql_real_escape_string(md5($_POST['password'])).'"');
if(mysql_num_rows($query) == 1)
{
$row = mysql_fetch_assoc($query);
if($row['Active'] == 1)
{
session_start();
$_SESSION['user_id'] = $row["ID"];
$_SESSION['username'] = $row["Username"];
$_SESSION['password'] = $row["Password"];
if(isset($_POST['autolog'])){
setcookie('autolog','loggato',time()+864000);
setcookie('user',$row["Username"],time()+864000);
setcookie('user_id',$row["ID"],time()+864000);
setcookie('pass',$row["Password"],time()+864000);
}
header("Location: mem.php");
}
else {
$error = 'Your membership was not activated. Please open the email that we sent and click on the activation link';
}
}
else {
$error = 'Login failed !';
}
}
else {
$error = 'Please user both your username and password to access your account';
}
}
?>
<?php if(isset($error)){ echo $error;}?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
User<input type="text" id="username" name="username" size="32" value="" />
Pass<input type="password" id="password" name="password" size="32" value="" />
Ricordami <input type="checkbox" name="autolog" value="1"/>
<input type="submit" name="Login" value="Login" />
</form>
questo è il check che sta nelle pagine riservate:
PHP:
<?php
if (!isset($_SESSION['username']) && !isset($_SESSION['password']) && !isset($_SESSION["user_id"])) {
$loggato = 0; //NON loggato
}else {
$loggato = 1; //LOGGATO!
}
if($_COOKIE['autolog'] == 'loggato'){
$_SESSION['username'] = $_COOKIE['user'];
$_SESSION['password'] = $_COOKIE['pass'];
$_SESSION['user_id'] = $_COOKIE["user_id"];
$loggato = 1;
//rinfresca cookies
$usern = $_SESSION['username'];
$passw = $_SESSION['password'];
$userid = $_SESSION['user_id'];
setcookie('autolog','loggato',time()+864000);
setcookie('user',$usern,time()+864000);
setcookie('user_id',$userid,time()+864000);
setcookie('pass',$passw,time()+864000);
}
?>
e questo è l'area riservata:
PHP:
<?php
require_once(dirname(__FILE__) . '/check.php');
?>
<strong><?php echo $usern;?></strong>
<strong><?php echo $userid;?></strong>
<strong><?php echo $passw;?></strong>
Grazie mille.
Per favore uno che mi aiuti.
Grazie.