top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to delete session cookies using PHP?

+6 votes
695 views
How to delete session cookies using PHP?
posted Apr 1, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

Deleting cookies using the setcookie function in PHP:

The setcookie() function can actually accept up to six arguments, but only one argument is actually required — and that is the cookie name. If you use the setcookie function, and just pass a cookie name without a value, then it will have the same effect as deleting the existing cookie with the same exact name. For example, to create a cookie called first_name, you use this line:

setcookie('first_name', 'vrije'); 

And to delete the first_name cookie, you would do this:

Example of deleting a cookie in PHP:

setcookie('first_name');  
answer Apr 8, 2016 by Vrije Mani Upadhyay
0 votes

session_destroy — Destroys all data registered to a session

Here is the small example that show how to destroy a php session

<?php
// Initialize the session.
session_start();

// Unset all of the session variables.
$_SESSION = array();

//Do  the programming inside here

// Finally, destroy the session.
session_destroy();
?>
answer Apr 7, 2016 by Prajwal C.m.
Similar Questions
+1 vote

I am trying to figure out if I can run my sessionpersistence script that I run with Apache to see if sessions persist between two tomcat sites on two separate servers. The load balancer has session persistence enabled but Iam unsure how to test it. My thought was that I would just add the following php script to check, but apparently I am doing something wrong. The script is this:

but it seems not to like it if I add it from the webapps directory or from inside a directory under that. Is there some special trick to running php from inside tomcat ? I have tomcat set up the same on both servers and am fronting it with Apache if that adds options for me.

0 votes

I am having trouble with session vars. I'm trying to implement the credit card direct pay method outlined here...

http://developer.authorize.net/api/dpm/

Basically, page 1 is my form that goes outside my site to the cc gateway company then comes back with a result... (PG2)

Problem: if I try to create session vars on page 1 - they don't work on page 2.

Am I correct in thinking that when this process leaves my site and goes to the gateway, then returns, it is similar to creating a new session and that is why the session vars don't remain active?

0 votes

I want to write online user module for my site and I want to check $_SESSION['userID'] to find all users id who loged in but when I echo this code its return only current user detail how I can see all sessions?

foreach($_SESSION as $k => $v)
{
echo $k."----------".$v;
}

or how I handle online users?

...