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
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;

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.