Hello friends ....
Today i am here with a problem for PHP developers....
The problem is when the user clicks on the logout button then PHP should destroy the session and redirect him to the login.PHP page...
But this is not happening... find out the problem...
Here is the code
User_index.php :
Today i am here with a problem for PHP developers....
The problem is when the user clicks on the logout button then PHP should destroy the session and redirect him to the login.PHP page...
But this is not happening... find out the problem...
Here is the code
User_index.php :
<?PHP
session_start();
if (!(isset($_SESSION['username']) && $_SESSION['username'] != '')) {
header ("Location: checklogin.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>MAP MY WAY</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta name="description" content="Google Maps API V3: Custom Directions Panel" />
<meta name="keywords" content="final_project" />
<meta name="author" content="Zohaib Tasnim" />
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?
v=3.exp&sensor=true&libraries=places"></script>
<link href="style.css" type="text/css" rel="stylesheet" />
<!--to disable the enter key-->
<script type="text/javascript">
function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = stopRKey;
</script>
</head>
<body>
<div id="mapCanvas"> </div>
<div id="box">
<a id="btns"> welcome <?php echo($_SESSION['username']); ?></a>
<a id="btns" href="profile.html"> My Profile</a>
<a id="btns" href="logout.php"> logout</a>
<p class="or">[OR]</p>
<div class="directionInputs">
<form action="address_insert.php" name="form2" method="post">
<p><label>A</label><input type="text" value="" name="loc_a"
id="dirSource" /></p>
<p><label>B</label><input type="text" value="" name="loc_b"
id="dirDestination" /></p>
<a href="#getDirections" id="getDirections">Get Directions</a>
<a href="#reset" id="paneReset">Reset</a>
<a id="btns"><input name="submit" class="btns" type="submit" value="Save
Address" /></a>
</form>
</div>
<div id="directionSteps">
<p class="msg">Direction Steps Will Render Here</p>
</div>
<!--<a href="#toggleBtn" id="paneToggle" class="out"><</a>-->
</div>
<script type="text/javascript" src="sample.js"></script>
</body>
</html>
And here is the logout.php
And here is the logout.php
<?php
session_start();
<?php
session_start();
session_destroy();
session_destroy();
if (session_destroy()){
header("location:login.php");
}
if (session_destroy()){
header("location:login.php");
}
else {
echo"there was some problem";
else {
echo"there was some problem";
}
}
?>
?>
Find out what is the problem....
remove in first line session_start(); in logout.php page keep remaining
ReplyDeletehttps://www.youtube.com/channel/UCVd5QKIss6Kka504YFt06gQ
thank you for reply.... i will try this...
Deletejust remove 2nd line session_destroy();
ReplyDeletethank you for reply.... i will try this...
Deletejust remove session_destroy(); which is out of if statement and also problem in index.php file stop key function that you pass event in that function argument while calling time but if not pass then from where it get event variable value.
ReplyDeletethank you for reply.... i will try this...
DeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteTry This code:
ReplyDeletesession_start();
$unset = time()-60*60*24*365*10;
session_unset();
setcookie("user", $user, $unset, "/", "Your URL");
ob_start();
ob_end_flush();
session_destroy();
header("Location: index.php");
thanks .... i will try this....
DeleteCan you follow the below codes and comments
ReplyDeleteUser_index.php head section look like this
//session_start(); //Remove this line because session need to be stated on "checklogin.php" not here
if (!(isset($_SESSION['username']) && $_SESSION['username'] != '')) {
header ("Location: checklogin.php");
}
logout.php looks like this
Can you follow the below codes and comments
ReplyDeleteUser_index.php head section remove this
//session_start(); //Remove this line because session need to be stated on "checklogin.php" not here
logout.php remove this
//session_start(); Remove this line because session has bees already started.
//session_destroy(); Remove this line bcoz below you are using this on conditional statement. by Magendiran
first in User_Profile.php
ReplyDeleteif (!(isset($_SESSION['username']) || $_SESSION['username'] == '')) {
header ("Location: checklogin.php");
}
and in logout.php file
session_start();
session_destroy();
header("location:login.php");