473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

End sessions by id.

16
I am new to PHP and I am building a PHP blog/user system thing. It's coming together pretty well. Right now I just got the user system running. Im using the session code form this tut. I found that when I delete a user from the database the user is still logged in. When I develop further it will cause problems for sure. So I was thinking I could store the users last session's id in the db. And then when I run delete the user also run a script that would end a session by it's id. Is there any way to do that? I looked around but couldn't find any.
Mar 24 '09 #1
13 2159
TheServant
1,168 Expert 1GB
Will you be deleting users often while they could still be online? THere are a few different ways. I am not sure, but maybe you can do as you say and store the session id in the database which can be recalled by session_id() and then cleared, or maybe something with session_destroy()?

I think you need to work hard at working out if you should be deleting from your database, because if someone is using your system, surely they want confidence that they have control on when it is deleted? By leaving it in their hands they can delete it and then run a session_destroy() to log them out.

I'll have a look around for remote session_destroying for you.
Mar 24 '09 #2
l3mon
16
I looked around but didn't see anything. I was thinking something like this.

<?php
session_destroy($sessionid);
?>
Mar 25 '09 #3
TheServant
1,168 Expert 1GB
SOunds like a plan. Really you should do session_unset() and session_destroy() together so that there is no way of keeping those variables alive. Give it a go and let me know how it turns out.
Mar 25 '09 #4
l3mon
16
No dice.
Warning: Wrong parameter count for session_destroy() in .../PHP/test.php on line 4
The code I was using:
<?php
$id = $_GET['id'];
session_unset($id);
session_destroy($id);
?>
So it's not failing the session_unset, however it's not doing anything (I tested both alone as well)
Mar 25 '09 #5
TheServant
1,168 Expert 1GB
I must apologise, I cannot test this stuff while I'm at work, and I was hoping for someone to be able to solve this off the top of their head. Try setting your session as the target session using:
Expand|Select|Wrap|Line Numbers
  1. $id = $_GET['id'];
  2. session_id($id);
  3. session_unset();
  4. session_destroy();
Mar 25 '09 #6
l3mon
16
Nope:
Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in /home8/boagloba/public_html/site3-phnx/PHP/test.php on line 5
And no worries about not being able to test it. The fact that your helping is wonderful!
Mar 25 '09 #7
numberwhun
3,509 Expert Mod 2GB
@l3mon
Correct me if I am wrong TheServant, but I think that the session_destroy() function does not take any arguments. That would be why you are getting the error(s).

Plus, the unset mentioned should only be used for older, deprecated code. Instead, you should use:

Expand|Select|Wrap|Line Numbers
  1. $_SESSION = array();
  2.  
Regards,

Jeff
Mar 25 '09 #8
l3mon
16
@numberwhun
I am really new to PHP; only about a week or so and I don't know where I would plugin my session id.
Mar 25 '09 #9
numberwhun
3,509 Expert Mod 2GB
@l3mon
That's ok, I am not exactly a veteran myself, but you need to know how to use the php online manual.

Take a look at and read this page. You will see that none of the examples use a session id as it kills the active session. Read the comments below as well as plenty is explained. Also, read the other command(s) pages off on the left side.

Its important to know your resources and how to use them. This one is invaluable.

Regards,

Jeff
Mar 25 '09 #10
TheServant
1,168 Expert 1GB
@numberwhun
Yeah, that's what I thought but couldn't test it at the time. Anyway, l3mon, you had before $_GET['id']? How do you get that session? I ask because from my understanding, or lack of it, you should be able to set your session with session_id()? If it says that there is no session initialized, you have forgotten session_start(), are getting the wrong id with $_GET['id'], or it doesn't work how I thought.

Unfortunately I have not had much time at home to help out, so just going through some things that I would test for if I was at home :P
Mar 25 '09 #11
Markus
6,050 Expert 4TB
Hey, guys.

OP, how're you setting your session? May we take a peek, please.

Thanks

- markus.
Mar 25 '09 #12
l3mon
16
@TheServant
I just took the id out of the cookie it automatically set in my browser.
Mar 26 '09 #13
l3mon
16


I know that that is right because I tried to modifies the content of cookie and it messed up but when I put it back to what it was it worked fine.
Mar 26 '09 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: The Plankmeister | last post by:
Hi... I'm trying my hardest to understand fully how sessions work and how best to use them. However, all I can find is information that doesn't tell me anything other than that sessions store...
13
by: jing_li | last post by:
Hi, you all, I am a newbee for php and I need your help. One of my coworker and I are both developing a webpage for our project using php. We have a copy of the same files in different location...
3
by: Maxime Ducharme | last post by:
Hi group We have a problem with sessions in one of our sites. Sessions are used to store login info & some other infos (no objects are stored in sessions). We are using Windows 2000 Server...
3
by: Will Woodhull | last post by:
Hi, I'm new here-- I've been reading the group for a couple of days. Nice group; I like the way n00b33 questions are handled. I've been using a Javascript routine in index.html to determine a...
2
by: Steve Franks | last post by:
According to the docs you tell ASP.NET to use cookieless sessions by setting a value in the config.web file. However, what if I wanted to determine at run time whether or not I wanted to use...
12
by: D. Shane Fowlkes | last post by:
This is a repost (pasted below). Since my original post, I've double checked the system clock and set all IIS Session Timeout values to 10 minutes. Still ...the problem occurs. I've also...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
22
by: magic_hat60622 | last post by:
Hi all. I've got an app that dumps a user id into a session after successful login. the login page is http://www.mydomain.com/login.php. If the user visits pages on my site without the www (i.e.,...
13
Frinavale
by: Frinavale | last post by:
One of the most fundamental topics in web design is understanding how to pass information collected on one web page to another web page. There are many different ways you could do this: Cookies,...
3
Atli
by: Atli | last post by:
Introduction: Sessions are one of the simplest and more powerful tools in a web developers arsenal. This tool is invaluable in dynamic web page development and it is one of those things every...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.