/    Sign up×
Community /Pin to ProfileBookmark

$_session problems

Hi At the bottom of my banner there is a strip that gives the users name: the name is set visa $_session[‘first_name’]

The problem is that if the user does not click the logout button the session remians active but from time to time when you go back to the page the wrong name is displayed which is not the users name at all.

any idea why this is happening.

Also how would I kill the session when have left the login area of more then 5 minutes.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Jan 23.2007 — I think that the issue you had with session variables, in this case $_SESSION['user_name'], is probably still not resolved (name duplicity).

To "automatically" kill a session after 5 minutes, use this:[code=php]<?php
ini_set("session.gc_maxlifetime", "300"); // 300 seconds
?>[/code]
Copy linkTweet thisAlerts:
@kprocauthorJan 23.2007 — Hi nightshift58 thank you for the post.

Should I be going through all my pages to check for this duplication problem.

also, the code that you provided does it take into consideration that the user is still active and then once there not active for five min it kills the session or does it kill the session that is started on each page after 5 minutes.



I'm not sure how to work that in to my exsisting code.

should I add it at the top of each page
Copy linkTweet thisAlerts:
@NightShift58Jan 23.2007 — Should I be going through all my pages to check for this duplication problem.[/quote]In the other thread, you had mentioned that you had changed the session variable names and reported that it had solved your problem. Isn't that the case?does it take into consideration that the user is still active and ...[/quote]Every time the user starts a page where you set the session.gc_maxlifetime, the "max lifetime" starts again - in this case, the session gets another 5 minutes.I'm not sure how to work that in to my exsisting code. should I add it at the top of each page[/QUOTE]Yes.
Copy linkTweet thisAlerts:
@kprocauthorJan 24.2007 — I did not change the session variable name on all pages, just the one that was creating problems. There are many pages that uses the same process.

So I should place the code that you provided just after my session start. thank you for the help.
Copy linkTweet thisAlerts:
@kprocauthorJan 24.2007 — Hi I think I figured out part of the problem.

When a member logs in their information is pulled from the database using $_session['']. the [''] is filled in with the table column name .

When the user logs in that is when the initial session is set.

I posted the code to my login page which sets the registration on another post.

throughout all my other pages information is shared about other members with the logged in member which requires that I query the same table and pull the same column names from the members table.

I add

<?php

ini_set("session.gc_maxlifetime", "300"); // 300 seconds

?>

to a page and left it for five minutes then did a refresh and it show the login members first name and another members last name.


any help is excellent
Copy linkTweet thisAlerts:
@kprocauthorJan 24.2007 — after all this and the help I have it figured out

I was not setting my session variable correctly
[code=php]
$_SESSION['fname'] = $row['first_name'];
$_SESSION['lname'] = $row['last_name'];
[/code]
×

Success!

Help @kproc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...