.htaccess php_value

Started on the old forum in January 2010 · view the original in the archive · old links redirect here

19 replies · 3,150 views · started 16 years ago · 1 min read

5 participants
PoV@rEsK Junior · 18 posts #1

I wrote into .htaccess line of code: php_value session.gc_maxlifetime 20 But after 20 seconds session is not destroyed. What problems are can be?

PoV@rEsK Junior · 18 posts #2

Full content of .htaccess file is it: php_value session.use_cookies 0 php_value session.gc_maxlifetime 20 php_value session.name SID = = = = = And i have not a access to the php.ini file.

GumSlone Administrator Principal · 1,690 posts #3

have you tried to add ini_set(); in to your script? like:

ini_set('session.use_cookies',0);
ini_set('session.gc_maxlifetime',20);
ini_set('session.name','SID');

to test which value is set do this:

echo ini_get("session.gc_maxlifetime");

there is also another way like

session_cache_expire(1); //1 minute
session_name("SID");

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

PoV@rEsK Junior · 18 posts #5

= = = = = index.php = = = = =

<?php ini_set('session.use_cookies',0); ini_set('session.gc_maxlifetime',20); ini_set('session.name','SID'); session_start(); $_SESSION["key"] = "Session alive "; echo '[Go to another page](#)'; ?>

= = = = = the another.page = = = = =

<?php session_start(); if(isset($_SESSION["key"])) { echo $_SESSION["key"]; } else { echo "Session died "; } echo 'Refresh this page after 25 seconds please to see result ... '; echo 'Value of session.gc_maxlifetime is "'.ini_get("session.gc_maxlifetime").'"'; ?>

This ^ example. It's right? Does not work...

PoV@rEsK Junior · 18 posts #6

And why my profile and profiles of other users on this forum are look like this: User Name: 147258a User Title: Junior Member Last Activity: 03-09-08 05:50 Your profile is also looks such as above.

manavworld Developer · 118 posts #7

GumSlone wrote: have you tried to add ini_set(); in to your script? like:

ini_set('session.use_cookies',0);
ini_set('session.gc_maxlifetime',20);
ini_set('session.name','SID');

to test which value is set do this:

echo ini_get("session.gc_maxlifetime");

there is also another way like

session_cache_expire(1); //1 minute
session_name("SID");

wow, its luk lyk amazing, but will u give me proper information where i can put this code?

subzero Super moderator Fellow · 3,954 posts #8

like any idiot knows lol

BEFORE YOUR HEADERS OMFG DUDE!!!

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

GumSlone Administrator Principal · 1,690 posts #9

PoV@rEsK wrote: = = = = = index.php = = = = =

<?php ini_set('session.use_cookies',0); ini_set('session.gc_maxlifetime',20); ini_set('session.name','SID'); session_start(); $_SESSION["key"] = "Session alive "; echo '[Go to another page](#)'; ?>

= = = = = the another.page = = = = =

<?php session_start(); if(isset($_SESSION["key"])) { echo $_SESSION["key"]; } else { echo "Session died "; } echo 'Refresh this page after 25 seconds please to see result ... '; echo 'Value of session.gc_maxlifetime is "'.ini_get("session.gc_maxlifetime").'"'; ?>

This ^ example. It's right? Does not work...

you have to include this:

ini_set('session.use_cookies',0);
ini_set('session.gc_maxlifetime',20);
ini_set('session.name','SID');

to every page.

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

PoV@rEsK Junior · 18 posts #10
      • sessions_including.php * * *
<?php ini_set('session.use_cookies',0); ini_set('session.gc_maxlifetime',20); ini_set('session.name','SID'); session_start(); ?>
      • index.php * * *
<?php require("sessions_including.php"); $_SESSION["key"] = "Session alive "; echo '[Go to another page](#)'; ?>
      • another_page.php * * *
<?php require("sessions_including.php"); if(isset($_SESSION["key"])) { echo $_SESSION["key"]; } else { echo "Session died "; } echo 'Refresh this page after 25 seconds please to see result ... '; echo 'Value of session.gc_maxlifetime is "'.ini_get("session.gc_maxlifetime").'"'; ?>
PoV@rEsK Junior · 18 posts #11

It every time outputs that "Session alive" but output of the "Value of session.gc_maxlifetime" is 20. When i come in to another_page.php i wait for 25 seconds then i refresh this page but it still outputs that "Session alive"... why??? Even if I clear cookie and cache. . .

ori Lead · 512 posts #12

20 = 20 minutes if im right... my site has sessions active for 1 year lol but logout kills the session using unset()

GumSlone Administrator Principal · 1,690 posts #13

ori wrote: 20 = 20 minutes if im right... my site has sessions active for 1 year lol but logout kills the session using unset()

no its seconds

this should work:

header("Cache-Control: no-cache, must-revalidate");
ini_set('session.use_cookies',0);
ini_set('session.gc_maxlifetime',20);
ini_set('session.gc_probability',1);
ini_set('session.gc_divisor',1);
ini_set('session.name','SID');
session_start();

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

GumSlone Administrator Principal · 1,690 posts #14

or you can do this too:

<?php
header("Cache-Control: no-cache, must-revalidate"); 
$session_lifetime = 20;
ini_set('session.use_cookies',0); 
ini_set('session.gc_maxlifetime',$session_lifetime ); 
ini_set('session.gc_probability',1); 
ini_set('session.gc_divisor',1); 
ini_set('session.name','SID'); 
session_start(); 
?>
      • index.php * * *
<?php
require("sessions_including.php");
$_SESSION["key"] = "Session alive<br /><br />";
$_SESSION["create_time"] = time(); 
echo '<a href="another_page.php?'.SID.'">Go to another page</a>';
?>
      • another_page.php * * *
<?php
require("sessions_including.php");

if((time()-$session_lifetime) > $_SESSION["create_time"]){session_destroy(); @unset($_SESSION);}

if(isset($_SESSION["key"])) {
echo $_SESSION["key"];
}
else {
echo "Session died<br /><br />";
}
echo 'Refresh this page after 25 seconds please to see result ...<br />';
echo 'Value of session.gc_maxlifetime is "'.ini_get("session.gc_maxlifetime").'"';
?>

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

PoV@rEsK Junior · 18 posts #15

GumSlone, your first example is works, and as i found out it will work too:

      • .htaccess * * * php_value session.use_cookies 0 php_value session.gc_maxlifetime 20 php_value session.gc_probability 1 php_value session.gc_divisor 1 php_value session.name SID

But there is one thing that i can't understand. See below...

PoV@rEsK Junior · 18 posts #16

The link of reclam from example above, it's not my, it's hoster's )))))

GumSlone Administrator Principal · 1,690 posts #17

PoV@rEsK wrote: GumSlone, your first example is works, and as i found out it will work too:

      • .htaccess * * * php_value session.use_cookies 0 php_value session.gc_maxlifetime 20 php_value session.gc_probability 1 php_value session.gc_divisor 1 php_value session.name SID

But there is one thing that i can't understand. See below...

yes i have tested it at my host too, only after you refresh the page the session is destroyed, hmm dont know why.

This is what i got from php.net site:

session.gc_probability integer session.gc_probability in conjunction with session.gc_divisor is used to manage probability that the gc (garbage collection) routine is started. Defaults to 1. See session.gc_divisor for details. session.gc_divisor integer session.gc_divisor coupled with session.gc_probability defines the probability that the gc (garbage collection) process is started on every session initialization. The probability is calculated by using gc_probability/gc_divisor, e.g. 1/100 means there is a 1% chance that the GC process starts on each request. session.gc_divisor defaults to 100.

probably the garbage collector is runing only when refresh the page, i think this should not happen when you have many users at your site.

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

ori Lead · 512 posts #18

i have similar prob the session destroys but unless u click back or reload the page still thinks its active so a redirect is good idea but its not really needed

i thought that was just a cookie issue

Guest #20

Works ..with minor modifications .. .. Thank you

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close