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
https://forums.phpfreaks.com/topic/112922-help-getting-a-session-name/
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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.