Forum Moderators: coopster
I set up a cookie for a "remember me" thing. It uses the session_id() as the value. Here's the function for finding out if someone's logged in or not, and if the cookie is there:
27 function checkLoggedIn($status){
28 switch($status){
29 case "yes":
30 if((!$_SESSION["loggedIn"]) & ($_COOKIE['mem']!= '' )){
31 $query = mysql_query("SELECT * FROM users WHERE sessionid = '{$_COOKIE['mem']}");
32 $crumb = mysql_fetch_array($query);
33 $login = $crumb[1];
34 $_SESSION["login"]=$crumb[1];
35 $_SESSION["loggedIn"]=true;
36 header("Location: site.com/logged_in.php);
37 } else if (!$_SESSION["loggedIn"]){
38 header("Location: site.com/not_logged_in.php");
39 exit;
40 }
41 break;
42 case "no":
43 if($_SESSION["loggedIn"]){
44 header("Location: site.com/logged_in.php);
45 }
46 break;
47 }
48 return true;
49 }
Now, when a user returns to the site, two errors happen:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/yup/function.php on line 32
Warning: Cannot modify header information - headers already sent by (output started at /home/yup/function.php:32) in /home/yup/function.php on line 36
When I refresh the site, those errors go away (because loggedin = true).
So, I'm guessing I need to rewrite that bit about the cookie. Can anyone help?
Thanks.
don't use the mysql_query() function without precising what it is supposed to do if it didn't work.
Moreover, you have an obvious MySQL syntax error... just put the following:
so,
$query = mysql_query("SELECT * FROM users WHERE sessionid = '".$_COOKIE['mem']."'")OR die(mysql_error); The last problem is dued to an HTML output which is dued itself to the display of the mySQL error, so if the first works, the second should work too.
SepanG
France