Jump to content

Help getting a session name


Darkmatter5

Recommended Posts

Say I have a user logged in on my site where the session's name is the primary key of the member record called member_id. when a member logs in I set a field named logged_in in the members record to 1.  When the user wants to log out I want to set the field to 0, if I have the following log out script

<?php
include 'library/config.inc.php';
require('C:\wamp\www\library\opendb.php');
$pagedb = "members";

session_start();

if(session_is_registered('member_id')) {
	session_unset();
	session_destroy();
	mysql_query("UPDATE " .$dbname. "." .$pagedb.
				" SET logged_in = '0'
				WHERE member_id = '" .$member_id. "'
				") or die(mysql_error());
	echo "Logged out!";
//		header("Location: index.php");
} else {
	echo "Not logged in!";
//		header("Location: index.php");
}
?>

 

How can I pass the member_id to this page from other pages so I can reference which member_id to set the field to?  As I read this it sounds a bit confusing, let me know if this doesn't make sense and I'll elaborate.

Link to comment
Share on other sites

if i understand this you have the answer already

 

if(session_is_registered('member_id')) {

                $member_id = $_SESSION['member_id']; //add this line

	session_unset();
	session_destroy();
	mysql_query("UPDATE " .$dbname. "." .$pagedb.
				" SET logged_in = '0'
				WHERE member_id = '" .$member_id. "'
				") or die(mysql_error());

 

give that a shot

-c

Link to comment
Share on other sites

As far as I could tell my code seemed good, but the member_id didn't seem to pass.  So here's another idea.  I put in more script to see exactly what is being passed into the mysql_query.  Here's the code

<?php
include 'library/config.inc.php';
require('C:\wamp\www\library\opendb.php');
$pagedb = "members";

session_start();

if(session_is_registered('member_id')) {
	session_unset();
	session_destroy();
	mysql_query("UPDATE " .$dbname. "." .$pagedb.
				" SET logged_in = '0'
				WHERE member_id = '" .$member_id. "'
				") or die(mysql_error());
                //NEW CODE IS THE FOLLOWING LINE
	echo "UPDATE " .$dbname. "." .$pagedb. " SET logged_in = '0' WHERE member_id = '" .$member_id. "'";
	echo "<br>Logged out!<br>
	<a href='index.php'>Index</a>";
//		header("Location: index.php");
} else {
	echo "Not logged in!<br>
	<a href='index.php'>Index</a>";
//		header("Location: index.php");
}
?>

 

When it's output it says

UPDATE ecabinet.members SET logged_in = '0' WHERE member_id = ''
Logged out!
Index

 

So as you can see the member_id isn't being passed.  See the thing is I have a link on my index.php file that says this:

<a href="logout.php">Logout</a>

 

Is there anything I need to add to the link to pass the member_id?

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.