The Problem Is When A Person Checks 'Remember Me' And Logs In, Then His Data Isn't Shown. When He Logs In Without Checking 'Remember Me', His Data Is Shown!
Everything Works Fine! Except The User's Data Isn't Shown.
This Is The Notice I Get : Undefined index: user_id in C:\xampp\htdocs\vu\func\user.func.php on line 17
My user_data function!
function user_data() { $args = func_get_args () ; $fields = '`'.implode('` , `',$args).'`' ; $id = (isset($_COOKIE['user_id'])) ? (int)$_COOKIE['user_id'] : $_SESSION['user_id']; $query = mysql_query ("SELECT $fields FROM `users` WHERE `user_id`='".$id."' ") ; $query_result = mysql_fetch_assoc($query) ; foreach ($args as $field) { $args [$field] = $query_result[$field] ; } return $args ; }My Login Page :
<?php if (logged_in()) { $user_data = user_data ('name') ; echo 'Hello! '.$user_data['name'] ; } else { ?> <form action="" method="POST"> <p> Email : <input type="email" name="login_email" /> Password : <input type="password" name="login_password" /> <input type="checkbox" name="rememberme" /> Remember Me <input type="submit" value="Log in" /> </p> </form> <?php } if (isset ($_POST['login_email'], $_POST['login_password'])) { $login_email = $_POST['login_email'] ; $login_password = $_POST['login_password'] ; $rememberme = $_POST['rememberme'] ; $errors = array() ; if (empty ($login_email) || empty ($login_password)) { $errors[] = 'Email and password required.'; } else { $login = login_check ($login_email,$login_password) ; if ($login === false) { $errors[] = 'Please type in a valid email/password.' ; } } if (!empty ($errors)) { foreach ($errors as $error) { echo '<li>'.$error.'<br />' ; } } else { if ($rememberme=='on') setcookie ('username', $login_email, time()+7200) ; else if ($rememberme=="") $_SESSION['user_id'] = $login ; header ('Location: index.php') ; exit () ; } } ?>