Jump to content

Recommended Posts

setcookie("user_id", $_SESSION['user_id'], time()+60*60*24*60, "/");
			  setcookie("user_name", $_SESSION['user_name'], time()+60*60*24*60, "/");

 

i use that for my login.php when somone logs in..

 

But if i login and go to school and come back and hit refresh usally around 5-8hours im logged off...

 

but if i hit refresh after 3-4hours im still logged in why?

Link to comment
https://forums.phpfreaks.com/topic/181936-keeps-loggin-me-out-in-5hours/
Share on other sites

Does it do it on other browsers/computers? It could just be a setting on your computer wiping the cookie data...

 

No cause all my other sites i use like phpfreaks/other forums im still loggedin

 

Is there something wrong with my code? is it setting it to unlimited time with all those **?

time()+60*60*24*60

 

That sets the timeout to be 60 days from now. So techincally you should not have to "re-login" within 60 days.

 

It could be something with your code, hard to tell without seeing it... Something to the effect of a script that goes and wipes out the session after a certain time etc. Could also be in your configuration files for session timeout, after x amount of time the session will expire.

 

A quick test you can do to see if it is the script or server is create a simple script

 

<?php
if (!isset($_COOKIE['mycookietest'])) {
    setcookie("mycookietest", "test", time()+60*60*24*60, "/");
}else {
    echo "mycookietest has been set to: " . $_COOKIE['mycookietest'];
}
?>

 

Run that then adjust your time on your box to be 6 hours and then refresh the page, see if the cookie is still active (no clue if this will work but sounds like a reasonable test).

 

If it does stay the chances are it is your script that is tossing the cookie somewhere... (given that it is a valid test, I cannot see why it would not be).

Adjust time in my box? you mean buttom corner of my desktop ?

 

Yea, when I refer to "box" it generally means your computer. A lot of IT people call them boxes because...well most of them are as a big as a box and store a ton of junk inside :) (at least that is how I define the term).

Adjust time in my box? you mean buttom corner of my desktop ?

 

Yea, when I refer to "box" it generally means your computer. A lot of IT people call them boxes because...well most of them are as a big as a box and store a ton of junk inside :) (at least that is how I define the term).

 

 

Adjust time to be 6 hours?

 

I dont get it, so make add 6 Hours to it?

 

 

but isn't that script for 60days? im lost

 

 

in any event.. 6hours wont help if it's 60days

i reffer to tham as a system but im supposed to be in the proffession of it support, otherwise i would proabbly call it a box or tower or PC any of these naming methods basically mean and relate to the same thing.

 

about the origional question, did you create the script yourself or is it modified from an example in some way, if so i preffer to look at the example and code my own version, if you dont know what something does then research it and you may not even want to add it in or you may want to replace it, this could be the cause of your issue.

 

if you coded the whole script yourself then it is probably some of the other code that is affecting your script, you could also try calculating the sum of 60*60*24*60 and using the number directly or as an alternative try placing the mathematics in brackets to specify presidence of the order that the total is calculated.

Ok, take a step back and breathe. The reason I said 6 hours is because I basically mimiced the cookie your current script was setting. So doing this test everything is setup like the cookies are being set in your script. Going ahead 6 hours, which is the time you stated that you are logged out of your site automatically, will test if the issue is in your script, on your server or on your computer.

 

Basically we are just trying to narrow down what the culprit maybe. Does that make sense? So adding 6 hours to your computer's time the cookie should still be valid, cause it is well under the 60 days like the cookie is set for. If it does get deleted then we can rule out your script and chances are it is something in your computer or on the server that is causing the issues. This is the act of testing and debugging.

Ok, take a step back and breathe. The reason I said 6 hours is because I basically mimiced the cookie your current script was setting. So doing this test everything is setup like the cookies are being set in your script. Going ahead 6 hours, which is the time you stated that you are logged out of your site automatically, will test if the issue is in your script, on your server or on your computer.

 

Basically we are just trying to narrow down what the culprit maybe. Does that make sense? So adding 6 hours to your computer's time the cookie should still be valid, cause it is well under the 60 days like the cookie is set for. If it does get deleted then we can rule out your script and chances are it is something in your computer or on the server that is causing the issues. This is the act of testing and debugging.

 

 

Werid cause i set my computer uplike 3days and refresh and im still logged in..

 

 

 

but if i go to school and come back or gone for a period of long time it's always loggin me off..

 

wth is going on

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.