Jump to content

Clearing a session variable


BrettCarr

Recommended Posts

Hi people I have a ajax send that sends an php $SESSION array to the server side does some stuff adds the records to the mysql database

This all works fine

My problem is that when the ajax php is done i want to clear the $_SESSION['batcharray'] with unset. So i thought i would send a repsonse back from ajax with the number 1 in it and if it is one clear the $_SESSION['barcharray'] So the user can start a new batch of records.. But it keeps clearing it not allowing me to add anymore records I am totally lost. I haven't posted code becuase i have no idear and i would be waisting your time any advice would be great im desperate

Link to comment
https://forums.phpfreaks.com/topic/195892-clearing-a-session-variable/
Share on other sites

just use $_SESSION['barcharray'] =

 

that should work and replace the original one.

ok im doing this

function addDatadbRecv(data)   

                {

                        $_SESSION['batcharray'] = data;

                }

But i get this is the responce tab

 

$_SESSION is not defined

$_SESSION['batcharray'] = data;

Could you please post your code?


function addDatadb()	
			{
					myarray = <?= json_encode($_SESSION['batcharray']) ?>;
					send( '/ajax/arrayclean.php', 'myarray=' + myarray, null , addDatadbRecv );
			}

function addDatadbRecv(data)	
			{
				$_SESSION['batcharray'] = data;
			}

this is whats in ajax/arrayclean.php


<?PHP
include_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.php');
$db = new Database();
$db->connect();

$batcharry = $_REQUEST['myarray'];
$parts = array_map(create_function('$e', 'return implode("','", $e);'), array_chunk(explode(',', $batcharry), 13));
//var_dump($parts);
		foreach ($parts as $value)
			{
				$comma_separated = implode("','", $value);					
				//var_dump($comma_separated);
				eval("\$comma_separated = \"$comma_separated\";");									
				$myquery = "INSERT INTO batch_import VALUES(null,'$comma_separated','0');";
				//echo $myquery . "<br />";
				$db->query($myquery);
			}
			if (isset($_REQUEST['myarray']))
			{

				unset($_REQUEST['myarray']);
				echo $_REQUEST['myarray'];
			}


?>

so when$_REQUEST['myarray'] is emptied im sending back to client side and want to replace whatsin $_SESSION['batcharray'] with whats in data.... nothing

If this is Javascript (which it looks like)

 

function addDatadb()   
            {
                  myarray = <?= json_encode($_SESSION['batcharray']) ?>;
                  send( '/ajax/arrayclean.php', 'myarray=' + myarray, null , addDatadbRecv );
            }
            
   function addDatadbRecv(data)   
            {
               $_SESSION['batcharray'] = data;
            }

 

$_SESSION means nothing to it. You'll need to clear $_SESSION['batcharray'] on the server.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.