prowind Posted July 9, 2011 Share Posted July 9, 2011 i have this code: <?php session_start(); include("connect.php"); $cookie = $_POST['setcookie']; $time = time(); $user = mysql_real_escape_string($_POST['username']); $pass = mysql_real_escape_string($_POST['password']); if(empty($user) || empty($pass)) { die("Username and/or password field(s) is/are empty"); } else { // Check if he has the right info. $query = mysql_query("SELECT * FROM users WHERE username = '$user' AND password = '$pass'"); $check = mysql_num_rows($query); if($check > 0) { $_SESSION['logged'] = 1; $_SESSION['user'] = $user; if($cookie) { // Check to see if the 'setcookie' box was ticked to remember the user setcookie("te['user']", $user, $time + 9999999); // Sets the cookie username setcookie("te['pass']", $pass, $time + 9999999); // Sets the cookie password } header('Location: index.php'); } else echo "Wrong login or/and password"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html dir="rtl"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=windows-1255" /> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> </body> </html> everything is working here.. just not the cookies.. i have a "remember me" button in my logging form and im trying to create cookie that will remember the username and password.. but it doesnt seems to work. i'v created a check.php code to check if it created the cookies: <?php session_start(); echo $_COOKIE['te']['user']; ?> it shows blank page so the cookies were never created.. help? Quote Link to comment https://forums.phpfreaks.com/topic/241517-problem-with-cookies-in-logging-form/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 9, 2011 Share Posted July 9, 2011 Because your setcookie statement has single-quotes around user - "te['user']", the array key is literally - " 'user' " You would need to use echo $_COOKIE['te']["'user'"]; or simply remove the single-quotes so that your setcookie is - "te[user]" Quote Link to comment https://forums.phpfreaks.com/topic/241517-problem-with-cookies-in-logging-form/#findComment-1240602 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.