php logout script

Php logout script

Before creating the logout, make sure you have a working with PHP login Script.

To make your user log out from the restricted area you will need:
a logout link from a restricted page
a php script to check if the user logged out then redirect to the login page or index page.

Logout php script

 <?php 
restricted.php 
 
//starting the session
session_start();

//checking if a log SESSION VARIABLE has been set or not.
if( !isset($_SESSION['log']) || ($_SESSION['log'] != 'in') ){
 //if the user is not allowed, display a message and a link to go back to login page or index page.
 echo "You are not allowed. <a href="index.php">back to login page</a>";
 
 exit();
}
 // CODE FOR USER LOG OUT 
if(isset($_GET['log']) && ($_GET['log']=='out')){
 //if the user logged out then delete any SESSION variables
 session_destroy();
 
 //then redirect to login page
 header('location:index.php');
}//end log out

?> 
<!-- RESTRICTED PAGE HTML GOES HERE -->
<!-- add a LOGOUT link before the form -->
<p><a href="?log=out">log out</a> </p>

Leave a Reply

Related Posts: You may like

Extract Total Number of Image And Missing Alt Attribute using php

How to extract Heading tags using PHP from string

How to remove whitespace from string using php

Remove All Special Characters From String PHP

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Download Instagram Videos & Photos.

Download Now

CURRENCY CONVERTER

Real Time Currency Converter

Convert Now

ROBOST.TXT GEN.

Robots.txt File Creater

Create Now

HTML MINIFIER

Compress yout HTML Code

Minify Now

CSS MINIFIER

Compress yout CSS Code

Minify Now

JAVASCRIPT MINIFIER

Compress yout JavaScript Code

Minify Now

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.