0

I am new to PHP I need a little help in my php login script... I had 3 pages

1. index.html (user type username and password )
2. login.php
3. logout.php

ie index.html
<html>
/Main Page ///////
<body>
<form action="login.php" method="post">
<input name="uname" type="text" id="uname" />
<input name="pass" type="text" id="pass" />
<input type="submit" name="Submit" value="Submit" />
</form>

</body>
</html>

login.php

<html>
<?php
$uname=$_POST;
$pass=$_POST;
if ($uname=='ram' && $pass=='mypass'){
echo "Welcome RAM ";
}else{
$ok='index.html';
header('Location: ' . $ok);
}
?>
<a href="logout.php">Logout</a>
<html>

logout.php
<?php
echo "SIGN OUT ";
?>


Now the problem is after we sign out and return back to previous page using browser and then thelogin.php page came with the username . From journals I read about cookie delete and session... But i am not aware about it please help me what changes I would made for that ... Please help me...................
Regards
Rajeesh

4
Contributors
6
Replies
7
Views
9 Years
Discussion Span
Last Post by Shanti C
0

use session sothat u can destroy the session while logging out

Please let me know how to do it please........

0

I have gathered the below script from the official documentation at: http://au2.php.net/manual/en/function.session-destroy.php

<?php
session_start(); //must be at beginning of page

//in here is any miscellaneous logout data such as mysql scripts.

//Below destroys the session
$_SESSION = array();
if (isset($_COOKIE[session_name()])) {
    setcookie(session_name(), '', time()-42000, '/');
}
session_destroy();
?>

So the above script I have mentioned can go into the logout file with the any other logout data going where the comments are.

0

In which page to add this is in logout.php or login.php

The code I mentioned earlier is meant to be in logout.php as it removes the session.

0

you can use this code when you have used sessions in your login page...
use this code at your logout page:

session_unregister('username');
session_destroy();
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.