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

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
intellisourceAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
intellisourceConnect With a Mentor Author Commented:
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
 
h4hardySr. Software EnginnerCommented:
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
 
intellisourceAuthor Commented:
it is above any content being written - except the header tags of the page which are before the if $q's are processed.
0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
intellisourceAuthor Commented:
oh and i did attempt clearing with $_SESSION['VARIABLE'] = ''; before the session_destroy(); but to no avail.
0
 
intellisourceAuthor Commented:
oki moved session_start() to the top of the page but to no avail -_-
0
 
h4hardySr. Software EnginnerCommented:
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
 
intellisourceAuthor Commented:
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
 
intellisourceAuthor Commented:
here is the session info on the server - perhaps anybody can relate anything meaningful in my experience from this:
session.jpg
0
 
intellisourceAuthor Commented:
thanks for the efforts guys, seems not all of our focus'/clarities are where they need to be hehe :)
0
 
Ray PaseurCommented:
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
All Courses

From novice to tech pro — start learning today.