FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » how to unset session variable when leaving page
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: how to unset session variable when leaving page [message #174683 is a reply to message #174681] Mon, 27 June 2011 21:29 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
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(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: debugging with Netbeans
Next Topic: get members who have birthday this week
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 10:39:34 GMT 2024

Total time taken to generate the page: 0.05042 seconds