Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #2418
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: how to unset session variable when leaving page |
| Date | 2011-07-01 05:36 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <iuk4fp$knh$1@dont-email.me> (permalink) |
| References | <075a7a75-e93d-4bac-b94f-f336aa7ef1be@d1g2000yqm.googlegroups.com> <57e91bee-b606-473f-8ba8-020927f01a53@d1g2000yqm.googlegroups.com> |
On 6/30/2011 11:41 PM, Martin wrote:
> On Jun 27, 7:48 pm, Co<vonclausow...@gmail.com> wrote:
>> Hi All,
>>
>> I use a session variable to search for certain data in my records.
>> When a submit button is hit a session var gets filled with what I am
>> looking for.
>>
>> if(isset($_POST['listByq'])&& $_POST['listByq'] != "add") {
>> unset($_SESSION['listByq']);
>> unset($_SESSION['valueByq']);
>> $option = "";
>> $_SESSION['listByq'] = $_POST['listByq'];
>> if(isset($_POST['fname'])) { $_SESSION['valueByq'] =
>> $_POST['fname']; }
>> if(isset($_POST['country'])) { $_SESSION['valueByq'] =
>> $_POST['country']; }
>>
>> }
>>
>> If I browse to the next page but still using the same search query I
>> check again:
>>
>> // IF WE HAVE A SESSION THEN FILL $OPTION WITH A VALUE
>> if(isset($_SESSION['listByq'])) {
>> $option = $_SESSION['listByq'];
>> if ($option == "by_country") {
>> $country = $_SESSION['valueByq']; //$_POST['country'];
>>
>> $queryString = "WHERE country='$country' AND email_activated='1'";
>> $queryMsg = "Showing Members from the country you searched for";
>>
>> } else if ($option == "by_firstname") {
>>
>> $firstname = $_SESSION['valueByq']; //
>> $_POST['fname'];
>> $firstname = stripslashes($firstname);
>> $firstname = strip_tags($firstname);
>> $firstname = eregi_replace("`", "", $firstname);
>> $firstname = mysql_real_escape_string($firstname);
>> $queryString = "WHERE rank LIKE '%$firstname%' OR firstname LIKE '%
>> $firstname%' OR lastname LIKE '%$firstname%' AND email_activated='1'";
>> $queryMsg = "Showing Members with the name you searched for";
>>
>> } else if ($option == "newest_members") {
>>
>> $queryString = "WHERE email_activated='1' ORDER BY id DESC";
>> $queryMsg = "Showing Newest to Oldest Members";
>>
>> }
>> } // end of if(isset($_SESSION....
>>
>> This is all working like I want but when the user leaves the page and
>> returns later the session var is still
>> filled with the last search. I tried to clear the session var at the
>> beginning of the page but then when I browse
>> to the next page the session var will also be emptied.
>>
>> Is it possible to clear the session var when leaving the page?
>>
>> Marco
>
> I've had to do this before and simply added a body onunload event
> listener to the page:
>
> <body onunload="clearSession()">
>
> Calls a javascript function:
>
> function clearSession(){
> // here make a request to a PHP script called clear_session.php
> }
>
> Finally the clear_session.php script:
>
> <?php
> unset($_SESSION['myVar'];
> ?>
>
> Martin.
>
Which is not at all reliable. Better to code the server side properly.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
how to unset session variable when leaving page Co <vonclausowitz@gmail.com> - 2011-06-27 11:48 -0700
Re: how to unset session variable when leaving page Martin <warwound@gmail.com> - 2011-06-30 20:41 -0700
Re: how to unset session variable when leaving page Jerry Stuckle <jstucklex@attglobal.net> - 2011-07-01 05:36 -0400
Re: how to unset session variable when leaving page Denis McMahon <denis.m.f.mcmahon@gmail.com> - 2011-07-01 12:00 +0000
Re: how to unset session variable when leaving page Jerry Stuckle <jstucklex@attglobal.net> - 2011-07-01 12:35 -0400
Re: how to unset session variable when leaving page dougatmilmacdotcom@example.com (Doug Miller) - 2011-07-01 11:50 +0000
Re: how to unset session variable when leaving page "Peter H. Coffin" <hellsop@ninehells.com> - 2011-07-01 16:58 -0500
Re: how to unset session variable when leaving page Martin <warwound@gmail.com> - 2011-07-01 02:01 -0700
csiph-web