Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #2357 > unrolled thread

how to unset session variable when leaving page

Started byCo <vonclausowitz@gmail.com>
First post2011-06-27 11:35 -0700
Last post2011-06-28 03:03 +0000
Articles 6 — 5 participants

Back to article view | Back to comp.lang.php


Contents

  how to unset session variable when leaving page Co <vonclausowitz@gmail.com> - 2011-06-27 11:35 -0700
    Re: how to unset session variable when leaving page Jerry Stuckle <jstucklex@attglobal.net> - 2011-06-27 17:29 -0400
      Re: how to unset session variable when leaving page unknown <not4email@all.invalid> - 2011-06-28 18:31 -0500
        Re: how to unset session variable when leaving page Jerry Stuckle <jstucklex@attglobal.net> - 2011-06-28 20:23 -0400
    Re: how to unset session variable when leaving page dougatmilmacdotcom@example.com (Doug Miller) - 2011-06-27 22:41 +0000
      Re: how to unset session variable when leaving page Mick Gurling <nospam@myemail.net> - 2011-06-28 03:03 +0000

#2357 — how to unset session variable when leaving page

FromCo <vonclausowitz@gmail.com>
Date2011-06-27 11:35 -0700
Subjecthow to unset session variable when leaving page
Message-ID<fdb4f334-c961-4c2c-809e-819767790b5c@x12g2000yql.googlegroups.com>
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

[toc] | [next] | [standalone]


#2359

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-06-27 17:29 -0400
Message-ID<iuasol$4si$1@dont-email.me>
In reply to#2357
On 6/27/2011 2:35 PM, Co 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

As you've been told many times.  PHP HAS NO IDEA WHEN THE USER LEAVES 
YOUR PAGE.  By the time the page shows up in the user's browser, the PHP 
script has completed and sent all its data to the client.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#2382

Fromunknown <not4email@all.invalid>
Date2011-06-28 18:31 -0500
Message-ID<qtok0758q05608jj8ohot7dle97fu8ktn4@4ax.com>
In reply to#2359
On Mon, 27 Jun 2011 17:29:55 -0400, Jerry Stuckle
<jstucklex@attglobal.net> wrote:

[done]

>
>As you've been told many times.  PHP HAS NO IDEA WHEN THE USER LEAVES 
>YOUR PAGE.  By the time the page shows up in the user's browser, the PHP 
>script has completed and sent all its data to the client.

Of course you COULD put one or more big DONE buttons (triggering
another PHP script) on the page and hope the user follows
instructions.

[toc] | [prev] | [next] | [standalone]


#2384

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-06-28 20:23 -0400
Message-ID<iudr97$263$2@dont-email.me>
In reply to#2382
On 6/28/2011 7:31 PM, unknown wrote:
> On Mon, 27 Jun 2011 17:29:55 -0400, Jerry Stuckle
> <jstucklex@attglobal.net>  wrote:
>
> [done]
>
>>
>> As you've been told many times.  PHP HAS NO IDEA WHEN THE USER LEAVES
>> YOUR PAGE.  By the time the page shows up in the user's browser, the PHP
>> script has completed and sent all its data to the client.
>
> Of course you COULD put one or more big DONE buttons (triggering
> another PHP script) on the page and hope the user follows
> instructions.

That doesn't solve the problem - because a large percentage of people don't.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#2363

Fromdougatmilmacdotcom@example.com (Doug Miller)
Date2011-06-27 22:41 +0000
Message-ID<iub0v0$t3r$1@dont-email.me>
In reply to#2357
In article <fdb4f334-c961-4c2c-809e-819767790b5c@x12g2000yql.googlegroups.com>, Co <vonclausowitz@gmail.com> wrote:
[snip lots of irrelevant stuff]
>Is it possible to clear the session var when leaving the page?

No. Think about it: your PHP script runs on *your server*. Suppose I'm 
visiting your web site, then navigate away to, say, Google. That page is 
served by *Google's* server -- how do you imagine that it might be possible 
for your server to know that I did that?

The *only* thing your PHP script knows about is what gets sent to it from the 
browser. There is no way at all by which your script can tell the difference 
between these scenarios, because *none* of them result in the browser sending 
anything to your script:
a) Your page is still displayed on my screen and I'm looking at it;
b) Your page is still displayed on my screen, but I'm no longer looking at it 
because I stepped out for coffee;
c) Your page is still open in my browser but I'm no longer looking at it 
because I'm watching something more interesting in a different tab;
d) Your page is no longer displayed on my screen because I navigated to some 
other web site;
e) Your page is no longer displayed on my screen because I turned my computer 
off and went to bed;
f) Your page is no longer displayed on my screen because alien invaders from 
Proxima Centauri have reduced my entire city to a glowing heap of radioactive 
slag.

[toc] | [prev] | [next] | [standalone]


#2365

FromMick Gurling <nospam@myemail.net>
Date2011-06-28 03:03 +0000
Message-ID<iubgas$l7v$1@dont-email.me>
In reply to#2363
We Proxima Centaurians would never do that!
We like Earthlings
(Especially with onions and a little Franks Red Hot Sauce).

On Mon, 27 Jun 2011 22:41:25 +0000, Doug Miller wrote:

> In article
> <fdb4f334-c961-4c2c-809e-819767790b5c@x12g2000yql.googlegroups.com>, Co
> <vonclausowitz@gmail.com> wrote: [snip lots of irrelevant stuff]
>>Is it possible to clear the session var when leaving the page?
> 
> No. Think about it: your PHP script runs on *your server*. Suppose I'm
> visiting your web site, then navigate away to, say, Google. That page is
> served by *Google's* server -- how do you imagine that it might be
> possible for your server to know that I did that?
> 
> The *only* thing your PHP script knows about is what gets sent to it
> from the browser. There is no way at all by which your script can tell
> the difference between these scenarios, because *none* of them result in
> the browser sending anything to your script:
> a) Your page is still displayed on my screen and I'm looking at it; b)
> Your page is still displayed on my screen, but I'm no longer looking at
> it because I stepped out for coffee;
> c) Your page is still open in my browser but I'm no longer looking at it
> because I'm watching something more interesting in a different tab; d)
> Your page is no longer displayed on my screen because I navigated to
> some other web site;
> e) Your page is no longer displayed on my screen because I turned my
> computer off and went to bed;
> f) Your page is no longer displayed on my screen because alien invaders
> from Proxima Centauri have reduced my entire city to a glowing heap of
> radioactive slag.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web