Solved

why do the session variables not get unset/destroyed? 0o

Posted on 2011-09-14
10
313 Views
Last Modified: 2012-05-12
hi there,

the page queries can be summarized as follows:

Query      Description
50      Retail Including VAT via s=SupplierID, p=PartNumber
51      Retail Including VAT + Discount via s=SupplierID, p=PartNumber & n=PercentageOff
52      Retail Including VAT Session Total
53      Retail Including VAT + Discount Session Total
54      Session Comments
55      Empty Session Variables then Clear Session

and this is how they are supposed to work in the following section of qtpq.php:

// unused functions, variable preperation & earlier working queries without sessions
$s = $_GET["s"];
if (!is_numeric($s)) {
	$s = 141;	
}
$q = $_GET["q"];
if (is_numeric($q)) {
	$q = intval($q);
	if ($q < 0) {
		$q = 0;
	} elseif ($q > 8 && $q < 50) {
		$q = 50;
	} elseif ($q > 55 && $q < 100) {
		$q = 100;
	} elseif ($q > 107) {
		$q = 100;
	}
} else {
	$q = 0;
}
$n = $_GET["n"];
if (!is_numeric($n)) {
	$n = 0;
}
$p = $_GET["p"];
// queries < 100 (50-55 as specified in reference)
} elseif ($q < 100) {
	session_start();
	if (!isset($_SESSION['comment'])) $_SESSION['comment'] = array();
	$tsql = "SELECT 
		CASE ".$q." 
		WHEN 50 THEN 									# Retail Including VAT
			(28_pricelists.decimal_RetailExcluding * 1.14) 
		WHEN 51 THEN 									# Retail Including VAT + Discount
			(28_pricelists.decimal_RetailExcluding * 1.14) * (1 - ".$n." / 100) 
		WHEN 52 THEN 									# Retail Including VAT Session Total
			\"".floatval($_SESSION['rtlvat'])."\" 
		WHEN 53 THEN 									# Retail Including VAT + Discount Session Total
			\"".floatval($_SESSION['rtlvatdisc'])."\" 
		WHEN 54 THEN 									# Return Comments
			\"".implode("<br/>\n",$_SESSION['comment'])."<br/>\n |||||||||| Retail Total R ".number_format(floatval($_SESSION['rtlvat']),2)."<br/>\n |||||||||| Discounted Total R ".number_format(floatval($_SESSION['rtlvatdisc']),2)."\" 
		WHEN 55 THEN 									# Empty Session Variables then Clear Session
			\"\" 
		END AS text_Result, 
			28_pricelists.text_PartNumber, 
			28_pricelists.text_Description 
	FROM 
		28_pricelists".(($q>51)?";":" 
	WHERE 
		28_pricelists.text_PartNumber = \"".$p."\" 
	LIMIT 1;");
	//echo $tsql;
	$result = mysql_query_errors($tsql , $conn , __FILE__ , __LINE__ , true );
	if ($result) {
		if ($row = mysql_fetch_array($result)) {
			if ($q == 50) {										// create / add session total incl. vat
				array_push($_SESSION['comment'], "||||| ".$row["text_PartNumber"]." || ".$row["text_Description"]." || R ".number_format(floatval($row["text_Result"]),2))." || ";
				if (!isset($_SESSION['rtlvat'])) {
					$_SESSION['rtlvat'] = floatval($row["text_Result"]);
				} else {
					$_SESSION['rtlvat'] = floatval($_SESSION['rtlvat']) + floatval($row["text_Result"]);
				}
			} elseif ($q == 51) {									// create / add session total incl. vat + discount, Empty Session Variables & Clear Session
				$_SESSION['comment'][count($_SESSION['comment'])-1] = $_SESSION['comment'][count($_SESSION['comment'])-1]." || ".$n."% || R ".number_format(floatval($row["text_Result"]),2)." ";
				if (!isset($_SESSION['rtlvatdisc'])) {
					$_SESSION['rtlvatdisc'] = floatval($row["text_Result"]);
				} else {
					$_SESSION['rtlvatdisc'] = floatval($_SESSION['rtlvatdisc']) + floatval($row["text_Result"]);
				}
			} elseif ($q - 52) {
				// do nothing. returns session total incl vat from mysql
			} elseif ($q = 53) {
				// do nothing, returns session total incl vat + disc from mysql
			} elseif ($q = 54) {
				// do nothing, returns session comments from mysql
			} elseif ($q = 55) {
				// Empty Retail Incl Vat Total
				unset($_SESSION['rtlvat']);
				// Empty Retail Incl Vat + Discount Total
				unset($_SESSION['rtlvatdisc']);
				// Empty Comments
				unset($_SESSION['comment']);
				// Finally, destroy the session.
				session_destroy();
			}
			echo (is_numeric($row["text_Result"]))?number_format(floatval($row["text_Result"]),2):$row["text_Result"];
		}
		mysql_free_result($result);
	}
// following query possibilities without sessions < 150

Open in new window


the url's where these can be seen in the order they should be used and how they act are:

Clear/Destroy Session Before Starting: http://www.intellisource.co.za/qtpq.php?q=55
Get Retail + Discount Total: http://www.intellisource.co.za/qtpq.php?q=53
Clear/Destroy Session When Done: http://www.intellisource.co.za/qtpq.php?q=55
now all seems as its supposed to, trying this procession once does seem to work. but try it for a second round and you will notice the session variables are NOT being cleared/destroyed. why is this and how can i resolve this issue?

many thanks in advance
0
Comment
Question by:intellisource
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 2
10 Comments
 
LVL 4

Expert Comment

by:h4hardy
ID: 36535216
you have to mentation the session_start() on the top of the pages.. else the session varibale not take place it's affect... also you can try like,

$_SESSION['YOUR_VARIBALE'] = '';

hope it will work.
0
 

Author Comment

by:intellisource
ID: 36535276
it is above any content being written - except the header tags of the page which are before the if $q's are processed.
0
 

Author Comment

by:intellisource
ID: 36535287
oh and i did attempt clearing with $_SESSION['VARIABLE'] = ''; before the session_destroy(); but to no avail.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:intellisource
ID: 36535350
oki moved session_start() to the top of the page but to no avail -_-
0
 
LVL 4

Expert Comment

by:h4hardy
ID: 36535353
you can try with the below code.. it's working fine..

<?php
session_start();
// unused functions, variable preperation & earlier working queries without sessions
$s = $_GET["s"];
if (!is_numeric($s)) {
        $s = 141;       
}
$q = $_GET["q"];
if (is_numeric($q)) {
        $q = intval($q);
        if ($q < 0) {
                $q = 0;
        } elseif ($q > 8 && $q < 50) {
                $q = 50;
        } elseif ($q > 55 && $q < 100) {
                $q = 100;
        } elseif ($q > 107) {
                $q = 100;
        }
} else {
        $q = 0;
}
$n = $_GET["n"];
if (!is_numeric($n)) {
        $n = 0;
}
$p = $_GET["p"];
// queries < 100 (50-55 as specified in reference)
} elseif ($q < 100) {
        
        if (!isset($_SESSION['comment'])) $_SESSION['comment'] = array();
        $tsql = "SELECT 
                CASE ".$q." 
                WHEN 50 THEN                                                                    # Retail Including VAT
                        (28_pricelists.decimal_RetailExcluding * 1.14) 
                WHEN 51 THEN                                                                    # Retail Including VAT + Discount
                        (28_pricelists.decimal_RetailExcluding * 1.14) * (1 - ".$n." / 100) 
                WHEN 52 THEN                                                                    # Retail Including VAT Session Total
                        \"".floatval($_SESSION['rtlvat'])."\" 
                WHEN 53 THEN                                                                    # Retail Including VAT + Discount Session Total
                        \"".floatval($_SESSION['rtlvatdisc'])."\" 
                WHEN 54 THEN                                                                    # Return Comments
                        \"".implode("<br/>\n",$_SESSION['comment'])."<br/>\n |||||||||| Retail Total R ".number_format(floatval($_SESSION['rtlvat']),2)."<br/>\n |||||||||| Discounted Total R ".number_format(floatval($_SESSION['rtlvatdisc']),2)."\" 
                WHEN 55 THEN                                                                    # Empty Session Variables then Clear Session
                        \"\" 
                END AS text_Result, 
                        28_pricelists.text_PartNumber, 
                        28_pricelists.text_Description 
        FROM 
                28_pricelists".(($q>51)?";":" 
        WHERE 
                28_pricelists.text_PartNumber = \"".$p."\" 
        LIMIT 1;");
        //echo $tsql;
        $result = mysql_query_errors($tsql , $conn , __FILE__ , __LINE__ , true );
        if ($result) {
                if ($row = mysql_fetch_array($result)) {
                        if ($q == 50) {                                                                         // create / add session total incl. vat
                                array_push($_SESSION['comment'], "||||| ".$row["text_PartNumber"]." || ".$row["text_Description"]." || R ".number_format(floatval($row["text_Result"]),2))." || ";
                                if (!isset($_SESSION['rtlvat'])) {
                                        $_SESSION['rtlvat'] = floatval($row["text_Result"]);
                                } else {
                                        $_SESSION['rtlvat'] = floatval($_SESSION['rtlvat']) + floatval($row["text_Result"]);
                                }
                        } elseif ($q == 51) {                                                                   // create / add session total incl. vat + discount, Empty Session Variables & Clear Session
                                $_SESSION['comment'][count($_SESSION['comment'])-1] = $_SESSION['comment'][count($_SESSION['comment'])-1]." || ".$n."% || R ".number_format(floatval($row["text_Result"]),2)." ";
                                if (!isset($_SESSION['rtlvatdisc'])) {
                                        $_SESSION['rtlvatdisc'] = floatval($row["text_Result"]);
                                } else {
                                        $_SESSION['rtlvatdisc'] = floatval($_SESSION['rtlvatdisc']) + floatval($row["text_Result"]);
                                }
                        } elseif ($q - 52) {
                                // do nothing. returns session total incl vat from mysql
                        } elseif ($q = 53) {
                                // do nothing, returns session total incl vat + disc from mysql
                        } elseif ($q = 54) {
                                // do nothing, returns session comments from mysql
                        } elseif ($q = 55) {
                                // Empty Retail Incl Vat Total
								$_SESSION['rtlvat'] = '';
								$_SESSION['rtlvatdisc'] = '';
								$_SESSION['comment'] = '';
                                unset($_SESSION['rtlvat']);

                                // Empty Retail Incl Vat + Discount Total
                                unset($_SESSION['rtlvatdisc']);
                                // Empty Comments
                                unset($_SESSION['comment']);
                                // Finally, destroy the session.
                                session_destroy();
                        }
                        echo (is_numeric($row["text_Result"]))?number_format(floatval($row["text_Result"]),2):$row["text_Result"];
                }
                mysql_free_result($result);
        }
// following query possibilities without sessions < 150

?>

Open in new window

0
 

Author Comment

by:intellisource
ID: 36535521
i wasnt going to paste the whole page's code here, just the section that uses these session variables, i forgot to add the header info which is as follows:
header('Cache-Control: no-cache');
header('Pragma: no-cache');
header("Content-type: text/plain; charset=utf-8");

Open in new window

the session_start() has been moved right to the top of the page, below the page identifying php comment and above the functions and variables as follows:
<?php
/*
Quicktext Pro AJAX XML RESPONSE
Version 2.2.3
*/
session_start();

Open in new window

yet it's still not working when i open http://www.intellisource.co.za/qtpq.php?q=55 -  yet this STILL does not clear or destroy the three session values despite adding the following above the unset's.
} elseif ($q = 55) {
	// set session vars to ''
	$_SESSION['rtlvat'] = '';
	$_SESSION['rtlvatdisc'] = '';
	$_SESSION['comment'] = '';
	// Empty Retail Incl Vat Total
	unset($_SESSION['rtlvat']);
	// Empty Retail Incl Vat + Discount Total
	unset($_SESSION['rtlvatdisc']);
	// Empty Comments
	unset($_SESSION['comment']);
	// Finally, destroy the session.
	session_destroy();
}

Open in new window

i am at a total loss here :(
0
 

Author Comment

by:intellisource
ID: 36535560
here is the session info on the server - perhaps anybody can relate anything meaningful in my experience from this:
session.jpg
0
 

Accepted Solution

by:
intellisource earned 0 total points
ID: 36535723
OMW!!! decided to inspect the flow of code, and i found the issue! the if statements NEVER went into 55 after the sql query! from 52 till 55 had typos: -, = instead of ==:
                        } elseif ($q - 52) {
                                // do nothing. returns session total incl vat from mysql
                        } elseif ($q = 53) {
                                // do nothing, returns session total incl vat + disc from mysql
                        } elseif ($q = 54) {
                                // do nothing, returns session comments from mysql
                        } elseif ($q = 55) {
                                // Empty Retail Incl Vat Total
                                unset($_SESSION['rtlvat']);
                                // Empty Retail Incl Vat + Discount Total
                                unset($_SESSION['rtlvatdisc']);
                                // Empty Comments
                                unset($_SESSION['comment']);
                                // Finally, destroy the session.
                                session_destroy();
                        }

Open in new window

0
 

Author Closing Comment

by:intellisource
ID: 36558733
thanks for the efforts guys, seems not all of our focus'/clarities are where they need to be hehe :)
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 36536572
The if/else constructs are confusing when you get more than one or two choices.  Learn about switch/case structures.  Your programming will be MUCH easier to understand, I promise!
http://us2.php.net/manual/en/control-structures.switch.php
0

Featured Post

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question