Jump to content

Sessions


N-Bomb(Nerd)

Recommended Posts

Hello,

 

I'm trying to write a session system to keep track of where users are at on my website. I've got the "session.save_path", and "session.gc_maxlifetime". How would I go about using session_id() and session_start() though. Currently I've got this code in a file called "session.php" and I'm going to include it into my php files. Here's the content of session.php:

 

$session = session_id();
if(empty($session)) session_start();

 

Since I'm using "session.save_path" I can see the session files as they're created, but after the maxlifetime the files never remove. Are they supposed to remove automatically? I really don't know what I'm doing with sessions or how to do this properly. :(

 

Help?  :'(

 

 

 

Link to comment
Share on other sites

Firstly, you need to put session_start at the top of any page you wish to use sessions on (read the manual).

 

I'm not really sure what you're trying to do when you say:

 

I'm trying to write a session system to keep track of where users are at on my website.

 

Can you elaborate?

Link to comment
Share on other sites

Firstly, you need to put session_start at the top of any page you wish to use sessions on (read the manual).

 

I'm not really sure what you're trying to do when you say:

 

I'm trying to write a session system to keep track of where users are at on my website.

 

Can you elaborate?

 

I have several pages on my website and I'm trying to create an "Online Users" system and it will say who's online and last seen and what page they're on. I want the user to be removed from the online list after 15 minutes of inactivity though. I was told that I need to start using sessions though to accomplish this and I've never worked with sessions before.

 

Link to comment
Share on other sites

Do you already have user system then?

 

There's no user system in place since there's no accounts needed.. so I guess I'm going to only track the ip. Only select people will receive the url to this website and I want to monitor their actions and where they go.. it's for a paper I'm writing.

Link to comment
Share on other sites

This is the sort of thing that you should be able to find tons of tutorials online for, and judging from your first post I don't think you've done much research on your own about this, or sessions for that matter.

 

Try Googling for some tutorials and come back here to asks questions if you run into coding problems.

Link to comment
Share on other sites

This is the sort of thing that you should be able to find tons of tutorials online for, and judging from your first post I don't think you've done much research on your own about this, or sessions for that matter.

 

Try Googling for some tutorials and come back here to asks questions if you run into coding problems.

 

My problem is that I've never used sessions before and I don't know what the heck I'm doing. I've wrote several classes and designed an entire website for this project and I'm down to the sessions and you're basically telling me to "Google It". I'm asking for advice on where I should go with this. Yes, the first post was not constructed very well, but I was in a rush. I'm actually on vacation with the family and I'm trying to squeeze in some work. Basically, here's what I want to do.

 

I have a website with various links and different pages. I'll be testing various people and giving them specific instructions on where to go on the website. I want to be able to track where they go on the website and when they went there. I'll won't be testing that many people so I'm not entirely concerned about using an account log-in system. Instead, I thought it would be easier to manage and track the users based off an ip address ( Please remember though - I've never really used php on a live environment so I've never had a use for sessions). I've got all of the website constructed already and I would simply like to add a php file at the top of each page for the session/database handling (database part is covered already). I've named my file session.php and I'll be including it in all files of my website with a unique identifying name so I can recognize the location of where the user is. Also, I would like the users session to expire after 15 minutes of inactivity.. how would I accomplish this?

 

I'm not very familiar with php sessions and I would learn (and feel more comfortable) if someone could help me get in the right direction.

 

Thanks.

Link to comment
Share on other sites

Oh, your issue is with sessions? Great! There are even more tutorials on how to use sessions, so yes, I am telling you to Google it.

 

This is a PHP code help forum, and you're not having any issue with your code. If you want to learn about sessions then use one of the many tutorials made for that, don't come here and ask a question like that.

Link to comment
Share on other sites

Oh, your issue is with sessions? Great! There are even more tutorials on how to use sessions, so yes, I am telling you to Google it.

 

This is a PHP code help forum, and you're not having any issue with your code. If you want to learn about sessions then use one of the many tutorials made for that, don't come here and ask a question like that.

 

Technically, I posted code and it's not working as I intended. I described what I'd like my code to be able to do and instead of just helping and explaining so everyone can learn you're just turning people away from the idea. What exactly have you contributed in this thread besides basically telling people to figure out how on their own?

Link to comment
Share on other sites

Based on your description of what you want, there is no reason to code anything.  You could also use a simple tracking cookie.  Tracking by IP is already built into every webserver in the web log!  Of course many different people may have the same IP address (see NAT).  There's literally 100's if not thousands of posts on this forum that involve php sessions, many of which have code and detailed information in them.  We have a search mechanism on the forum for that reason.  Alex was already kind enough to indicate that you need to issue session_start() at the top of each page.  Forget tutorials -- looking at the php manual pages on sessions for a few minutes should tell you everything you need to know.

 

I wrote this simple script to illustrate the simplicity of basic session handling the other day.

 

sessiontest.php

session_start();
if (!isset($_SESSION['pagecount'])) {
  $_SESSION['pagecount'] = 1;
} else {
  $_SESSION['pagecount']++;
}
echo 'Session tester';
echo "Ran this {$_SESSION['pagecount']} times.";

Link to comment
Share on other sites

Oh, your issue is with sessions? Great! There are even more tutorials on how to use sessions, so yes, I am telling you to Google it.

 

This is a PHP code help forum, and you're not having any issue with your code. If you want to learn about sessions then use one of the many tutorials made for that, don't come here and ask a question like that.

 

Technically, I posted code and it's not working as I intended. I described what I'd like my code to be able to do and instead of just helping and explaining so everyone can learn you're just turning people away from the idea. What exactly have you contributed in this thread besides basically telling people to figure out how on their own?

 

Please respect our community and the contributions of people like Alex.  He has answered 1000's of questions for people and that's why he has a blue badge next to his name.  We expect people to put some effort into learning the language and how to use it.    You posted 2 lines of code that shows you didn't even read a paragraph from the php manual.  My advice is to let it go, and stop attempting to defend the indefensible if you hope to get more help here.

Link to comment
Share on other sites

Oh, your issue is with sessions? Great! There are even more tutorials on how to use sessions, so yes, I am telling you to Google it.

 

This is a PHP code help forum, and you're not having any issue with your code. If you want to learn about sessions then use one of the many tutorials made for that, don't come here and ask a question like that.

 

Technically, I posted code and it's not working as I intended. I described what I'd like my code to be able to do and instead of just helping and explaining so everyone can learn you're just turning people away from the idea. What exactly have you contributed in this thread besides basically telling people to figure out how on their own?

I'm not looking to get into a semantics debate, or any other type of debate for that matter, with you. Your code demonstrated that you didn't try very hard to resolve this on your own, and it wasn't even very germane to your question in general.

 

My intention wasn't to stifle your learning, quite the contrary: You can find much more information regarding your query on google than I would ever be able to personal provide you with in this thread. Instead of arguing with me why don't you just take the advice and realize that you can find countless resources to learn what you're after, and without having to wait for someone to reply. Programmers have to be very resourceful, "Google it" is probably the best advice I can offer.

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.