0

Hello.

Please guide me how to start a session when a user clicks on login page and the info finds correct?
How to check this session on other pages which i want to secure from unauthorised access? if the session found then open this secure page, otherwise redirect the user to the index page?
and
How to end this session when user clicks on Logout?

Regards.

3
Contributors
2
Replies
26
Views
4 Years
Discussion Span
Last Post by OsaMasw
1

to start session put session_start() at the begining of your page
then make the login script and if it was true assign a variable to session and use this variable to check if the user looged or not, example:

<?php
session_start();
// check user in login database and if it was authorized
$_SESSION['user'] = $username ;
// In tha pages that you want to secure just
if ($_SESSION['user']) {
// show secure page
}else {
// redirect to login page
}
?>

but this method I gave is not secure enough so make sure to get the Idea from links above

to logout

<?
session_destroy();
// OR
unset($_SESSION['user']);
?>
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.