View Full Version : destroy cookie in logout

03-26-2010, 09:50 AM
I have a small login from with the basic username & password field. The values are then passed to a php page which redirects to the main login page, if the login was successful then a cookies value is set. Now i want to have a logout that will destroy my cookie once clicked, please find my code below:

if (isset($_COOKIE["user"])){

echo "<tr>";
echo "<td>Logged in As:</td>";

echo "</tr>";
echo "<tr>";
echo "<td>".$_SESSION['username'] . ";</td>";
echo "</tr>";
//Here i want a logout button that when clicked should destroy my cookie.
echo "</tr>

03-26-2010, 11:05 AM
Set the cookie with a date a few weeks or months in the past to ditch it.

03-26-2010, 11:09 AM
Thanks Matt, but how can I trigger the destroy session by a button?

03-26-2010, 01:48 PM
Add the required coded to unset session and change cookie's time in a page, say logout.php and then add a link to this page like

<a href="logout.php">Logout</a>