forumnz Posted February 15, 2008 Share Posted February 15, 2008 I'm using sessions and cookies for a login. I use the following code snippet as part of a login code and the code after to echo the cookie name, but it doesn't work. Why would this be? Thanks heaps, Sam. <?php if(mysql_num_rows($result)>0) { //Login Successful session_regenerate_id(); $member=mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['id']; $_SESSION['SESS_LEVEL_ID'] = $member['lvl']; session_write_close(); setcookie("user", "Alex Porter", time()+3600); } ?> <?php echo $_COOKIE["user"]; ?> Link to comment https://forums.phpfreaks.com/topic/91200-sessions-and-cookies/ Share on other sites More sharing options...
haku Posted February 15, 2008 Share Posted February 15, 2008 Try echoing the cookie right after its set to make sure its actually being set properly. (not going to solve your problem, but will help track it down). Link to comment https://forums.phpfreaks.com/topic/91200-sessions-and-cookies/#findComment-467445 Share on other sites More sharing options...
p2grace Posted February 15, 2008 Share Posted February 15, 2008 Also, are you calling the cookie on the same page in which you're setting it? If you're not you need to specify the save path in the cookie as well. setcookie("user", "Alex Porter", time()+3600,"/"); BTW are you declaring the session to be started anywhere? session_start() needs to be declared at the top of every page that uses a session variable. Link to comment https://forums.phpfreaks.com/topic/91200-sessions-and-cookies/#findComment-467458 Share on other sites More sharing options...
rameshfaj Posted February 15, 2008 Share Posted February 15, 2008 u can store the session simply: session_start(); session_register("test"); $_SESSION["test"]="testing session"; You can retrieve the value of the session using: $_SESSION["test"]; The cookies can be implemented as shown above. Link to comment https://forums.phpfreaks.com/topic/91200-sessions-and-cookies/#findComment-467559 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.