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.

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']);
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.