when i log in my pages move to home.php page,so i need how to relate home page with other pages,that the same person to get permission to access to other pages!

Dani AI

Generated

As recommended, session-based access control is the correct approach here, and was right to stress linking pages from the home page while guarding them with a session. A simple, secure workflow is: validate credentials on login, start a session, store a minimal user identifier and role, regenerate the session id, then redirect. Every protected page must start the same session and check that identifier before showing content.

Example (login handler):

<?php
session_start();
// after successful credential check
$_SESSION['user_id'] = $userId;
$_SESSION['username'] = $username;
$_SESSION['role'] = $role;
session_regenerate_id(true);
header('Location: home.php');
exit;
?>

Example (top of every protected page):

<?php
session_start();
if (empty($_SESSION['user_id'])) {
    header('Location: login.php');
    exit;
}
// optional role check
if ($_SESSION['role'] !== 'admin') {
    http_response_code(403);
    echo 'Forbidden';
    exit;
}
?>

Troubleshooting and quick security notes: session_start() must run before any output; call session_regenerate_id(true) on login to reduce fixation risk; do not store passwords in the session (store only an ID and role); enforce HTTPS and set session cookie flags (Secure, HttpOnly, SameSite) in production. If sessions do not persist, check php.ini settings (session.save_path, cookie params), file permissions, and browser cookie blocking. For authoritative details, see the PHP session documentation: PHP sessions.

Recommended Answers

All 2 Replies

Sorry can you please explain in more detail in what you trying to achieve, are you referring to a navigation bar, or some sort of access control relating to pages. If so sessions would be best bet.

you move to home page after login because may be you have set the home page path in header tag You can do this by another way. link your all pages from home page. but you should do this by creating session.only then your website will secure.

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.