gongpex Posted September 18, 2012 Share Posted September 18, 2012 (edited) Hello everyone, I had looking on google about how to delete php session or database after browser closed, I found it, but it must using ajax or javascript, to tell server to delete or set data so that it can logout or delete some feature, automatically after browser closed. My question : if browser disable javascript, Is it still can run that php code? Please the answer Many Thanks Edited September 18, 2012 by gong Link to comment Share on other sites More sharing options...
Ingolme Posted September 18, 2012 Share Posted September 18, 2012 No. Even if Javascript is enabled, detecting the browser closing is not very reliable. You must design your system to work in a way that doesn't require this detection. A lot of systems have a time-out. Link to comment Share on other sites More sharing options...
gongpex Posted September 18, 2012 Author Share Posted September 18, 2012 (edited) You must design your system to work in a way that doesn't require this detection. A lot of systems have a time-out. if I using date() or time() as system timeout, it's must be wait till it has reached the time that set out, of course to run the php code. (I ever test about auto delete on hubert.com, I deliberate to buy something till the basket shown $1.25 , and then I close my browser. But when I open it again, the product on basket had back to $0) Q : Is they using the "Timeout System" ? Thanks for answer. Edited September 18, 2012 by gong Link to comment Share on other sites More sharing options...
Ingolme Posted September 18, 2012 Share Posted September 18, 2012 They may have that information stored in a session. Sessions get destroyed as soon as the browser is closed. Link to comment Share on other sites More sharing options...
gongpex Posted September 18, 2012 Author Share Posted September 18, 2012 Sessions get destroyed as soon as the browser is closed. Q : Though user forgot to click "Sign Out" ? They may have that information stored in a session Q : So they create session though there is no user who login? Thanks for answer Link to comment Share on other sites More sharing options...
Ingolme Posted September 18, 2012 Share Posted September 18, 2012 On a website that doesn't use cookies, a user is logged out as soon as they close the browser. They don't need to click on any links. Sessions can be used for more purposes than login forms. Sessions are used to remember any information that needs to be used across different pages. Link to comment Share on other sites More sharing options...
gongpex Posted September 18, 2012 Author Share Posted September 18, 2012 On a website that doesn't use cookies, a user is logged out as soon as they close the browser. They don't need to click on any links. Q : So session is more good than cookies? (because some browser not support cookie) Sessions can be used for more purposes than login forms Q : In other word I should create session for visitor? thanks Link to comment Share on other sites More sharing options...
Ingolme Posted September 18, 2012 Share Posted September 18, 2012 You create sessions for data you want to store temporarily while a user is browsing the website.Cookies are for longer term data storage. Data that you want to keep for more than one day. PHP's session engine does use cookies internally, but it can work without it. Link to comment Share on other sites More sharing options...
gongpex Posted September 20, 2012 Author Share Posted September 20, 2012 (edited) Sorry for late reply, my internet connection was got trouble lately. Q : So, in short I should create session for my data same as when I made login form?(from the first step till complete) (Because last night I had try to create it on my file but after the session run, it can't be destroyed (using session_destroy()), and, though I close my browser, it still run (the session still exist)) Thanks____________________________________________________________________________________________ OFF Q : By the way how many language that you can speak besides English? Edited September 20, 2012 by gong Link to comment Share on other sites More sharing options...
Ingolme Posted September 20, 2012 Share Posted September 20, 2012 You only need one session, you store everything in the session variable. Both login information and other data can be stored in the $_SESSION array.As soon as you close your browser, everything that was in the $_SESSION array disappears. Link to comment Share on other sites More sharing options...
gongpex Posted September 21, 2012 Author Share Posted September 21, 2012 (edited) You only need one session Q : So if I using 2 session like this : <?php//this session for "temporary" datasession_start();if($_SESSION['mydata']){$test = "Welcome";}else{$test = "Bye";} //this is session for "user" data (this is not for auto log off)session_start();if(!$_SESSION['user']){$post = mysql_query("delete from user where name='user'");}else{echo"$post";}?> are prohibited? thanks Edited September 21, 2012 by gong Link to comment Share on other sites More sharing options...
birbal Posted September 21, 2012 Share Posted September 21, 2012 using it twice is redundant and it will throw a warning. when php encounter first session_start() it initialize new session or resume to previous session. Link to comment Share on other sites More sharing options...
thescientist Posted September 21, 2012 Share Posted September 21, 2012 Q : So if I using 2 session like this : <?php//this session for "temporary" datasession_start();if($_SESSION['mydata']){$test = "Welcome";}else{$test = "Bye";} //this is session for "user" data (this is not for auto log off)session_start();if(!$_SESSION['user']){$post = mysql_query("delete from user where name='user'");}else{echo"$post";}?> are prohibited? thanks you don't need 2 sessions. it's just an array, so you can just put as much data in it as you want, in whatever members you want. Link to comment Share on other sites More sharing options...
gongpex Posted September 22, 2012 Author Share Posted September 22, 2012 (edited) it's just an array, so you can just put as much data in it as you want, in whatever members you want. Q : Array? did you mean I can use array more than 1 like this code : <?php$_SESSION['v1'][1] = 'cake'; //or if($_SESSION['test']['member']){//some php code...}?> Note : I got this example from : http://php.net/manua...les.session.php please tell me Thanks Edited September 22, 2012 by gong Link to comment Share on other sites More sharing options...
Ingolme Posted September 22, 2012 Share Posted September 22, 2012 You can do that but only if you defined an array as one of the session values. $_SESSION['x'] = array();$_SESSION['x'][0] = "Something"; Everything needs to be given a value before it can be used. Link to comment Share on other sites More sharing options...
gongpex Posted September 22, 2012 Author Share Posted September 22, 2012 (edited) Everything needs to be given a value before it can be used. Q : if the session had given value, still it can given array? For example : <?$_SESSION['user'] = $user; // then I give it array -----> (1)$_SESSION['user'] = array();$_SESSION['user'][0] = $member;$_SESSION['user'][1] = $another_ thing;$_SESSION['user'][2] = 'hello';$_SESSION['user'][3] = 'cookie';$_SESSION['user'][4] = 'please_help_me'; // and finally, to display session : -----> (2) if($_SESSION['user'][0][1][2][3][4]){echo"that's good";}else{echo"hello";} //or -----> (3) if($_SESSION['user']){echo"that's good";}else{echo"hello";} //then if($_SESSION['user'][0]){echo"that's good";}else{echo"hello";} if($_SESSION['user'][1]){echo"that's good";}else{echo"hello";} //etc...?> Q : Code on above which is correct? Q : Number : -----> (2) or -----> (3) ?? thanks Edited September 22, 2012 by gong Link to comment Share on other sites More sharing options...
Ingolme Posted September 22, 2012 Share Posted September 22, 2012 You don't seem to understand arrays. You should read about them in the PHP tutorial. Link to comment Share on other sites More sharing options...
gongpex Posted September 24, 2012 Author Share Posted September 24, 2012 (edited) My question really not about on array, but it's about how to display session, this : <?if($_SESSION['user'][0][1][2][3][4]){echo"that's good";}else{echo"hello";}?> and this : <?if($_SESSION['user']){echo"that's good";}else{echo"hello";} //then if($_SESSION['user'][0]){echo"that's good";}else{echo"hello";} if($_SESSION['user'][1]){echo"that's good";}else{echo"hello";} //etc...?> from both on above, which one is correct? (that's my question). I know, of course the second option is the answer, if I using array Q : But if I using array in session repeatedly (like on second option), it's can be run or it's just redundant? Edited September 24, 2012 by gong Link to comment Share on other sites More sharing options...
thescientist Posted September 24, 2012 Share Posted September 24, 2012 (edited) Since $_SESSION is an array, it seems fairly obvious that one should know how to work with an array, as a pre-requisite. Edited September 24, 2012 by thescientist Link to comment Share on other sites More sharing options...
roy0702 Posted September 25, 2012 Share Posted September 25, 2012 (edited) On your second code, you can use loops(for, while, do while) inside your condition for shorter code.For your question, But if I using array in session repeatedly (like on second option), it's can be run or it's just redundant? Yes it will run but its not redundant unless you dont use any condition to stop your loop while manipulating the array. Edited September 25, 2012 by roy0702 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now