Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/241517-problem-with-cookies-in-logging-form/
Share on other sites

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]"

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.