Monday 30 June 2014

Task for PHP Developers...

Posted by Unknown | 03:13 Categories:
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 :

<?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">&#160;</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">&lt;</a>-->
</div>
<script type="text/javascript" src="sample.js"></script> 
  </body>
</html>
 

And here is the logout.php    

 

<?php session_start();

  session_destroy(); 

 if (session_destroy()){ header("location:login.php"); } 

 else { echo"there was some problem";  

} 

 ?> 

 

  Find out what is the problem....

 
 

Leave a reply....

 

14 comments:

  1. remove in first line session_start(); in logout.php page keep remaining

    https://www.youtube.com/channel/UCVd5QKIss6Kka504YFt06gQ

    ReplyDelete
    Replies
    1. thank you for reply.... i will try this...

      Delete
  2. just remove 2nd line session_destroy();

    ReplyDelete
    Replies
    1. thank you for reply.... i will try this...

      Delete
  3. just 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.

    ReplyDelete
    Replies
    1. thank you for reply.... i will try this...

      Delete
  4. This comment has been removed by the author.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Try This code:
    session_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");

    ReplyDelete
  7. Can you follow the below codes and comments
    User_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

    ReplyDelete
  8. Can you follow the below codes and comments
    User_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

    ReplyDelete
  9. first in User_Profile.php
    if (!(isset($_SESSION['username']) || $_SESSION['username'] == '')) {

    header ("Location: checklogin.php");

    }

    and in logout.php file
    session_start();
    session_destroy();
    header("location:login.php");

    ReplyDelete

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube