I have implemented a log-in routine that I thought captured SESSION variable to use through out all my PHP pages of my site. Here is the snippet of code which sets the session variables:

if($result) {
		if(mysql_num_rows($result) == 1) {
			//Login Successful
			session_regenerate_id();
			$member = mysql_fetch_assoc($result);
			$_SESSION['SESS_MEMBER_ID'] = $member['id'];
			$_SESSION['SESS_FIRST_NAME'] = $member['First_Name'];
			$_SESSION['SESS_LAST_NAME'] = $member['Last_Name'];
			$_SESSION['SESS_ADMIN'] = $member['ADMIN'];
			session_write_close();
			header("location: Service_Dates.php");
			exit();
		}else {
			//Login failed
			header("location: login-failed.php");
			exit();
		}
	}else {
		die("Query failed");
	}

On one of my pages, I am trying to see if the current logged in user is a volunteer who has already been signed up for a particular Event Date. Here is the code:

<?
  // Check to see if Logged In Volunteer is already in the signed up
$id_User = $_SESSION['SESS_MEMBER_ID'];  
$query2 = "select * FROM Ev_AvVolunteers  where id_Event='$id_Event' and id_Volunteer='$id_User'";
Print_r($query2);
//exit();
$results2 = mysql_query($query2) or die("Error performing query"); 

if ( $results2 ) { ?>

echo "<div align="left"><span class="style14">Remove Me<br />- <br />";

<? } else { ?>
	echo "<div align="left"><span class="style14">Add Me<br />- <br />";
<? } ?>

Shouldn't this grab my SESSION MEMBER ID?

My goal is to display a "Add Me" or "Remove Me" based on if they exist in the table.

Thanks ;-)

Member Avatar for diafol

make sure you've got session_start() at the top of each page.

Who is the best (cookies||session) ?

Member Avatar for diafol

Who is the best (cookies||session) ?

I noticed this thread is solved, but in my opinion, you should use both - depending on your needs. I wouldn't use one instead of the other. If the cookie data is essential to your app, perhaps you could build in some redundancy with sessions in case cookies are turned off by the user. I usually use cookies for 'returning users', like 'remember me' and config settings like language, themes etc. My language switchers usually write changes to cookies, but also write the current language to the session.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.