marklarah Posted May 9, 2008 Share Posted May 9, 2008 Code: <? include 'db.php'; if (isset($_POST['user'])){ $name = htmlentities($_POST['user']); $pass = md5($_POST['pass']); $result = mysql_query("SELECT * FROM `Players` WHERE `name` = '$name' AND `password` = '$pass'"); $num = mysql_num_rows($result); if ($num == 1){ $row = mysql_fetch_array($result); $key = $row['s_key']; setcookie("login", $key, time()+(60*60*24*365)); $s = 1; }else{ $fail = "<br><b><i><font color=\"red\">FISSION MAILED: Try Again</font></i></b>"; } }else{ $nl = 1; } ?> Problem I try to set the cookie, and I know it sets, as it lets me onto my page which has a "if(isset(....." Trouble is, Im echoing $key and $_COOKIE["login"] and printing all my cookies. I see $key (which is good). I DONT see $_COOKIE["login"] which should be the same as $key and i dont see the cookie appear in the printing of all my cookies. ??? Quote Link to comment https://forums.phpfreaks.com/topic/104887-solved-sessions/ Share on other sites More sharing options...
thomashw Posted May 9, 2008 Share Posted May 9, 2008 Try using print_r($_COOKIE) to see if it's being set properly. Quote Link to comment https://forums.phpfreaks.com/topic/104887-solved-sessions/#findComment-536796 Share on other sites More sharing options...
marklarah Posted May 9, 2008 Author Share Posted May 9, 2008 I am (I said i am) and its not. Quote Link to comment https://forums.phpfreaks.com/topic/104887-solved-sessions/#findComment-536801 Share on other sites More sharing options...
thomashw Posted May 9, 2008 Share Posted May 9, 2008 Hmm, I'm not positive but try this: $result = mysql_query( "SELECT * FROM Players WHERE name = {$name} AND password = {$pass}"); Quote Link to comment https://forums.phpfreaks.com/topic/104887-solved-sessions/#findComment-536807 Share on other sites More sharing options...
marklarah Posted May 9, 2008 Author Share Posted May 9, 2008 I can't at all get this to work. HELP!!!! Quote Link to comment https://forums.phpfreaks.com/topic/104887-solved-sessions/#findComment-537080 Share on other sites More sharing options...
nikefido Posted May 9, 2008 Share Posted May 9, 2008 use sessions? $_SESSION['login'] = $key Quote Link to comment https://forums.phpfreaks.com/topic/104887-solved-sessions/#findComment-537091 Share on other sites More sharing options...
marklarah Posted May 9, 2008 Author Share Posted May 9, 2008 Sessions only work for...one session. Quote Link to comment https://forums.phpfreaks.com/topic/104887-solved-sessions/#findComment-537121 Share on other sites More sharing options...
DarkWater Posted May 9, 2008 Share Posted May 9, 2008 Not if you put session_start() on the top of every file and change the session timeout value in php.ini. Cookies are horrid for login systems, no offense. Quote Link to comment https://forums.phpfreaks.com/topic/104887-solved-sessions/#findComment-537135 Share on other sites More sharing options...
PFMaBiSmAd Posted May 10, 2008 Share Posted May 10, 2008 Back to your first post, since you did not show where you were trying to display the cookie and expected $_COOKIE["login"] to be set, I will guess it was on the page where you were setting the cookie. If so, from the manual - Cookies will not become visible until the next loading of a page that the cookie should be visible for The $_COOKIE array is set when a page is requested and the browser sends the cookies to the server. Until you refresh a page or goto a different page $_COOKIE["login"] won't exist in the $_COOKIE array. If you are still not receiving the cookie, it is probably due to the path or host part of the domain changing or you are not actually setting the cookie due to a header problem. Quote Link to comment https://forums.phpfreaks.com/topic/104887-solved-sessions/#findComment-537222 Share on other sites More sharing options...
DarkWater Posted May 10, 2008 Share Posted May 10, 2008 I'd bet money that it's the former. He probably is trying to view the cookies on that page. >_> Quote Link to comment https://forums.phpfreaks.com/topic/104887-solved-sessions/#findComment-537224 Share on other sites More sharing options...
marklarah Posted May 18, 2008 Author Share Posted May 18, 2008 You are 100% correct...how n00bish of me. :( Perhaps pin this topic for when others make this mistake. Oh and I don't have access to php.ini. Quote Link to comment https://forums.phpfreaks.com/topic/104887-solved-sessions/#findComment-544061 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.