note 42902 added to function.session-cache-expire
| From: | "bermi�ferrer�" at rn2 dot php dot net | Date: | Thu, 03 Jun 2004 05:11:10 +0000 |
| Subject: | note 42902 added to function.session-cache-expire | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-70588@lists.php.net to get a copy of this message | ||
Hello,
Some of my customers asked me for a solution form their session not to expire when filling large
forms. Sometimes it takes them more than 2 hours to submit (phone, desk customers...).
I know I could have forced an ilayer to be refreshed dynamically and then include PHP code using
session_cache_expire() function, but this refreshing a page changes the form focus. So I found this
the only solution for them not to loose focus over their form element.
You can make a session not to expire by using this code.
Its a mixture of PHP and JavaScript and can be used on the same page were your code goes or it can
be called using an ilayer/iframe from your page.
I know this is not the best practice, but in some cases were user has no control over server globals
and security is not important this can help.
Here is the code.
<?
//First of all we prevent browsers from caching the image
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
//This piece of code returns a blank gif
if($_GET[img] > 0){
header('Content-Type: image/gif');
header("Content-Disposition: inline; filename=".time().".gif");
echo base64_decode(str_replace("\n","","
R0lGODlhAQABAPcAAAAAAAAAQAAAgAAA/
wAgAAAgQAAggAAg/wBAAABAQABAgABA/
wBgAABgQABggABg/wCAAACAQACAgACA/
wCgAACgQACggACg/wDAAADAQADAgADA/
wD/AAD/QAD/gAD//yAAACAAQCAAgCAA/
yAgACAgQCAggCAg/yBAACBAQCBAgCBA/
yBgACBgQCBggCBg/yCAACCAQCCAgCCA/
yCgACCgQCCggCCg/yDAACDAQCDAgCDA/
yD/ACD/QCD/gCD//0AAAEAAQEAAgEAA/
0AgAEAgQEAggEAg/0BAAEBAQEBAgEBA/
0BgAEBgQEBggEBg/0CAAECAQECAgECA/
0CgAECgQECggECg/0DAAEDAQEDAgEDA/
0D/AED/QED/gED//2AAAGAAQGAAgGAA/
2AgAGAgQGAggGAg/2BAAGBAQGBAgGBA/
2BgAGBgQGBggGBg/2CAAGCAQGCAgGCA/
2CgAGCgQGCggGCg/2DAAGDAQGDAgGDA/
2D/AGD/QGD/gGD//4AAAIAAQIAAgIAA/
4AgAIAgQIAggIAg/4BAAIBAQIBAgIBA/
4BgAIBgQIBggIBg/4CAAICAQICAgICA/
4CgAICgQICggICg/4DAAIDAQIDAgIDA/
4D/AID/QID/gID//6AAAKAAQKAAgKAA/
6AgAKAgQKAggKAg/6BAAKBAQKBAgKBA/
6BgAKBgQKBggKBg/6CAAKCAQKCAgKCA/
6CgAKCgQKCggKCg/6DAAKDAQKDAgKDA/
6D/AKD/QKD/gKD//8AAAMAAQMAAgMAA/
8AgAMAgQMAggMAg/8BAAMBAQMBAgMBA/
8BgAMBgQMBggMBg/8CAAMCAQMCAgMCA/
8CgAMCgQMCggMCg/8DAAMDAQMDAgMDA/
8D/AMD/QMD/gMD///8AAP8AQP8AgP8A/
/8gAP8gQP8ggP8g//9AAP9AQP9AgP9A/
/9gAP9gQP9ggP9g//+AAP+AQP+AgP+A/
/+gAP+gQP+ggP+g///AAP/AQP/AgP/A/
///AP//QP//gP///yH5BAEAAP8ALAAAA
AABAAEAAAgEAP8FBAA7"));
exit;
}
?>
<!-- HERE YOU CAN INSERT THE HTML OR PHP CODE -->
<img name="keepUpdated" src="<?=$_SELF?>?img=999">
<script language="Javascript">
<!--
var updateEvery = 30;//Seconds
function keepUpdated() {
timer=setTimeout("updateImage()",1000*updateEvery)
}
function updateImage() {
var randNum = Math.floor(Math.random()*999);
document.images.keepUpdated.src ="<?=$_SELF?>?img="+randNum;
keepUpdated();
}
keepUpdated();
//-->
</script>
I hope this can be helpful for someone.
Bermi Ferrer
----
Manual Page -- http://www.php.net/manual/en/function.session-cache-expire.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42902
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42902&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42902&report=yes
Search -- http://master.php.net/manage/user-notes.php