can any body explain how to manage sessions in the pages that without login no user must access any page and if tries to access using browser address bar then redirect it's location to login page.....pls do reply what to check to manage this by using session......

Member Avatar for Zagga

Hi vinay7868,

Do you mean you want to only allow logged in users to access a page?

Once a user has logged in, start a session and set a session variable.

session_start();
$_SESSION['username'] = "this_user";

At the start of any protected page, start the session again and check to see if $_SESSION['username'] exists, if not redirect to logout.php.

<?php
session_start();
if (!isset($_SESSION['username'])){
    header("Location: logout.php");
    exit();
}
?>
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.