Jump to content

Sessions and Cookies


forumnz

Recommended Posts

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
Share on other sites

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
Share on other sites

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.