0

I've created a web application page with login and session login

basically a

<?php session_start() ?>

do I really need to put this code on every page of my php ?
because session login only active on the first page after I do login..

Anyone.. Help me on this.. Thanks

3
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by vibhaJ
0

If you want to check that session's value on other pages, i.e. if user is logged in or not, then you have to add it on all top of page.

0

because after I login..when I try to click on the different page...I'm out of the session login ... that's the problem ..
So basically adding on every page.. will solve the problem yea ?

0

if I may know.. how to add cookies to remember the session everytime going back to the first page ? if I may know...

0

Do what I do, I created a "global.php" page and I include it at the top of every page. At the very top of "global.php" I have "session_start();" and below that I have all the variables I want to use, that way I can check if the user is logged in or not on every page, and use the variables I have set.

0

any sample or references ? Sorry I'm bit new with this .. :)

0

When user login you can set user's id in session.

$_SESSION['sess_userId'] = 12; // whatever id

Below is the function check if user is login or not.

function isUserLogin()
{
    if(!isset($_SESSION['sess_userId']))
    {       
        header("location:login.php");
        exit;
    }   
}

Now call this functionisUserLogin(); on top of page where you want guest restriction.
Not include in global.php otherwise all page will be asked for login.

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.