This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-09-08 22:42:34

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

PHP session lifetime

How do I set one?

Adding the following code to .htaccess still only makes sessions last a few hours.

Code:

php_value session.gc_maxlifetime 604800
php_value session.cookie_lifetime 604800

http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#2 2012-09-09 19:20:36

dvd4
Scratcher
Registered: 2010-06-30
Posts: 1000+

Re: PHP session lifetime

you can also set the php session cookie expire date in the php script too...


I made a mod  big_smile  It's called blook!
http://i49.tinypic.com/16ia63p.png

Offline

 

#3 2012-09-09 20:31:17

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: PHP session lifetime

dvd4 wrote:

you can also set the php session cookie expire date in the php script too...

How do I do that?

Edit: also, the cookie isn't the problem...the server throws out data that's older than a few hours.

Last edited by jvvg (2012-09-09 20:31:44)


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#4 2012-09-11 15:54:30

dvd4
Scratcher
Registered: 2010-06-30
Posts: 1000+

Re: PHP session lifetime

jvvg wrote:

dvd4 wrote:

you can also set the php session cookie expire date in the php script too...

How do I do that?

Edit: also, the cookie isn't the problem...the server throws out data that's older than a few hours.

why do you need sessions to last more than a few hours anyway ?


I made a mod  big_smile  It's called blook!
http://i49.tinypic.com/16ia63p.png

Offline

 

#5 2012-09-11 17:26:44

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: PHP session lifetime

dvd4 wrote:

jvvg wrote:

dvd4 wrote:

you can also set the php session cookie expire date in the php script too...

How do I do that?

Edit: also, the cookie isn't the problem...the server throws out data that's older than a few hours.

why do you need sessions to last more than a few hours anyway ?

Because I'm making a login that remembers the user.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#6 2012-09-11 21:02:22

GP1
Scratcher
Registered: 2009-07-06
Posts: 1000+

Re: PHP session lifetime

jvvg wrote:

dvd4 wrote:

jvvg wrote:


How do I do that?

Edit: also, the cookie isn't the problem...the server throws out data that's older than a few hours.

why do you need sessions to last more than a few hours anyway ?

Because I'm making a login that remembers the user.

So, it remembers that the user is logged in,  like facebook does? You can set a cookie to the same content as the session variable and set its expiration to far in the future. Then, in all your scripts (or at least some of them) have this code:

Code:

<?php
session_start();
$_SESSION['value'] = $_COOKIE['value'];
?>

But the client needs cookies on.


I am currently http://blocks.scratchr.org/API.php?user=GP1&amp;action=onlineStatus&amp;type=imagehttp://blocks.scratchr.org/API.php?user=GP1&amp;action=onlineStatus&amp;type=text and I finally got over 1000 posts.

Offline

 

#7 2012-09-11 21:04:18

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: PHP session lifetime

GP1 wrote:

jvvg wrote:

dvd4 wrote:


why do you need sessions to last more than a few hours anyway ?

Because I'm making a login that remembers the user.

So, it remembers that the user is logged in,  like facebook does? You can set a cookie to the same content as the session variable and set its expiration to far in the future. Then, in all your scripts (or at least some of them) have this code:

Code:

<?php
session_start();
$_SESSION['value'] = $_COOKIE['value'];
?>

But the client needs cookies on.

I would do that, but I need session variables to make it safer. Also, the cookie isn't the problem, it's the data.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#8 2012-09-12 12:20:14

dvd4
Scratcher
Registered: 2010-06-30
Posts: 1000+

Re: PHP session lifetime

jvvg wrote:

dvd4 wrote:

jvvg wrote:


How do I do that?

Edit: also, the cookie isn't the problem...the server throws out data that's older than a few hours.

why do you need sessions to last more than a few hours anyway ?

Because I'm making a login that remembers the user.

Why not just put the data in a database with mySQL ?


I made a mod  big_smile  It's called blook!
http://i49.tinypic.com/16ia63p.png

Offline

 

#9 2012-09-12 12:29:53

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: PHP session lifetime

dvd4 wrote:

jvvg wrote:

dvd4 wrote:


why do you need sessions to last more than a few hours anyway ?

Because I'm making a login that remembers the user.

Why not just put the data in a database with mySQL ?

Session variables are easier, and are more efficient, because they require fewer MySQL queries.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#10 2012-09-12 12:42:22

dvd4
Scratcher
Registered: 2010-06-30
Posts: 1000+

Re: PHP session lifetime

jvvg wrote:

dvd4 wrote:

jvvg wrote:


Because I'm making a login that remembers the user.

Why not just put the data in a database with mySQL ?

Session variables are easier, and are more efficient, because they require fewer MySQL queries.

Session variables are only temporary.


I made a mod  big_smile  It's called blook!
http://i49.tinypic.com/16ia63p.png

Offline

 

#11 2012-09-12 13:03:17

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: PHP session lifetime

dvd4 wrote:

jvvg wrote:

dvd4 wrote:


Why not just put the data in a database with mySQL ?

Session variables are easier, and are more efficient, because they require fewer MySQL queries.

Session variables are only temporary.

I am asking if there is a way to make them last longer (in this case, a week).


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#12 2012-09-12 13:24:30

dvd4
Scratcher
Registered: 2010-06-30
Posts: 1000+

Re: PHP session lifetime

jvvg wrote:

dvd4 wrote:

jvvg wrote:


Session variables are easier, and are more efficient, because they require fewer MySQL queries.

Session variables are only temporary.

I am asking if there is a way to make them last longer (in this case, a week).

probabally there is but I'm saying that there might not be a need to


I made a mod  big_smile  It's called blook!
http://i49.tinypic.com/16ia63p.png

Offline

 

#13 2012-09-12 15:23:36

XenoK
Scratcher
Registered: 2011-09-08
Posts: 1000+

Re: PHP session lifetime

Code:

    session_start();
    $timeout = 60; // Number of seconds until it times out.
     
    // Check if the timeout field exists.
    if(isset($_SESSION['timeout'])) {
        // See if the number of seconds since the last
        // visit is larger than the timeout period.
        $duration = time() - (int)$_SESSION['timeout'];
        if($duration > $timeout) {
            // Destroy the session and restart it.
            session_destroy();
            session_start();
        }
    }
     
    // Update the timout field with the current time.
    $_SESSION['timeout'] = time();

Eternity Tasks has launched into Alpha One! http://tasks.eternityincurakai.com/EI%20projects.png

Offline

 

#14 2012-09-12 15:54:33

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: PHP session lifetime

You code won't work XenoK, because the issue presents itself during the time a user is not actively browsing the site.

Offline

 

#15 2012-09-12 16:02:01

XenoK
Scratcher
Registered: 2011-09-08
Posts: 1000+

Re: PHP session lifetime

oh,  ok.  lets see....


Eternity Tasks has launched into Alpha One! http://tasks.eternityincurakai.com/EI%20projects.png

Offline

 

#16 2012-09-12 16:04:00

XenoK
Scratcher
Registered: 2011-09-08
Posts: 1000+

Re: PHP session lifetime

ini_set('session.save_path', /var/my-sessions-dir/);
ini_set('session.cookie_lifetime', 2592000);


would that work?  you'd place it before session_start();


Eternity Tasks has launched into Alpha One! http://tasks.eternityincurakai.com/EI%20projects.png

Offline

 

#17 2012-09-12 16:12:51

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: PHP session lifetime

XenoK wrote:

ini_set('session.save_path', /var/my-sessions-dir/);
ini_set('session.cookie_lifetime', 2592000);


would that work?  you'd place it before session_start();

No, because the problem isn't the cookie, it's the server side data.

Offline

 

#18 2012-09-12 17:36:10

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: PHP session lifetime

LS97 wrote:

XenoK wrote:

ini_set('session.save_path', /var/my-sessions-dir/);
ini_set('session.cookie_lifetime', 2592000);


would that work?  you'd place it before session_start();

No, because the problem isn't the cookie, it's the server side data.

I'm trying the code, and the save path might do the trick.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#19 2012-09-12 18:02:29

GP1
Scratcher
Registered: 2009-07-06
Posts: 1000+

Re: PHP session lifetime

Yeah, im guessing you can extend it in php.ini
But most free hosts wont let you access that... darn


I am currently http://blocks.scratchr.org/API.php?user=GP1&amp;action=onlineStatus&amp;type=imagehttp://blocks.scratchr.org/API.php?user=GP1&amp;action=onlineStatus&amp;type=text and I finally got over 1000 posts.

Offline

 

#20 2012-09-12 18:07:43

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: PHP session lifetime

GP1 wrote:

Yeah, im guessing you can extend it in php.ini
But most free hosts wont let you access that... darn

However, most do let you set PHP values in the .htaccess file.  wink


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#21 2012-09-12 22:40:51

GP1
Scratcher
Registered: 2009-07-06
Posts: 1000+

Re: PHP session lifetime

jvvg wrote:

GP1 wrote:

Yeah, im guessing you can extend it in php.ini
But most free hosts wont let you access that... darn

However, most do let you set PHP values in the .htaccess file.  wink

And I know nothing about .htaccess, because I use IIS instead of Apache. If I did I would let you know  smile


I am currently http://blocks.scratchr.org/API.php?user=GP1&amp;action=onlineStatus&amp;type=imagehttp://blocks.scratchr.org/API.php?user=GP1&amp;action=onlineStatus&amp;type=text and I finally got over 1000 posts.

Offline

 

#22 2012-09-13 07:25:38

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: PHP session lifetime

GP1 wrote:

jvvg wrote:

GP1 wrote:

Yeah, im guessing you can extend it in php.ini
But most free hosts wont let you access that... darn

However, most do let you set PHP values in the .htaccess file.  wink

And I know nothing about .htaccess, because I use IIS instead of Apache. If I did I would let you know  smile

Well, the code above works (when using the ini_set() function, but would probably work in .htaccess too).
Also, I like Apache more because it's free, it's open-source, it's more compatible, and it's a lot more popular.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

Board footer