Jump to content

delete values from a cookie


JKG

Recommended Posts

hello,

 

i have a cookie which contains ids, like: 123,33,45,67,89,

 

i then have a little ajax script and interface where the user can delete id's.

i can post these ids, which might look like this: 45,123,

 

how can i delete the posted id's from the cookie?

 

i would just grab the cookie, then reset it with the new values, but dont know the function that would strip the id's. trim()? strSOMETHING()?

 

 

CURRENT CODE:

 

JS:

 

<script>
function close_box(id){
$('span.close').click(function() {
	$(this).parent().fadeOut(400);	
  		$.post("<?php echo $html_dir . $scripts_dir . 'ajax/contact_ids_delete.php'; ?>",{idsToDelete:id});				   
});
}
</script>

(generated) HTML

	 echo "<div class=\"info-box\">".$i++.") ".$displayEmail['business_name']."<span onclick=\"close_box('".$displayEmail['ID'].",')\" class=\"close\">x</span></div>";

 

PHP

<?php
session_start();
if(isset($_POST['idsToDelete'])){
     $_SESSION['contact_id_del'] .= $_POST['idsToDelete'];
} else {
    $contact_id_trimmed = implode(',', array_unique(explode(',', $_SESSION['contact_id_del'])));
    echo $contact_id_trimmed;
    //setcookie("contact_ids", $contacts_trimmed, time()+1000, "/", "");
}
?>

 

thanks for your help, Joe

Link to comment
https://forums.phpfreaks.com/topic/245871-delete-values-from-a-cookie/
Share on other sites

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.