login - function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Tinebn
Forum Newbie
Posts: 2
Joined: Fri Jul 23, 2010 3:46 am

login - function

Post by Tinebn »

hi
I have made a simple login function - php+mysql , works fine !

my question is

when I login I get the site I have put in my code... and nothing else !

this site login has what i'am looking for... some pages everybody can see- others not and then there is the privacy site.

Do not understand the functions........ Then I can't program the login for my site

hope somebody cann give me the "picture" have is the data flows ??

Tine
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: login - function

Post by yacahuma »

I dont really understand where are you lost

You present a form in the login page. When the form is submitted you check that username and password exists in the database. If they exist you create a session

Code: Select all

if (credential in database)
{
    session_start()
    $_SESSION['user'] = a variable or an object containing user data
     header("Location: inside.php");  
}

at the top of every page you check if the session is set

Code: Select all

session_start();
if (!isset($_SESSION['user']) )
     header("Location: login.php");  
remember if you save an object in the session you have to include the session declaration before checking the session.

Thats it. There is not much else
Tinebn
Forum Newbie
Posts: 2
Joined: Fri Jul 23, 2010 3:46 am

Re: login - function

Post by Tinebn »

yacahuma wrote:I dont really understand where are you lost

You present a form in the login page. When the form is submitted you check that username and password exists in the database. If they exist you create a session

Code: Select all

if (credential in database)
{
    session_start()
    $_SESSION['user'] = a variable or an object containing user data
     header("Location: inside.php");  
}

at the top of every page you check if the session is set

Code: Select all

session_start();
if (!isset($_SESSION['user']) )
     header("Location: login.php");  
remember if you save an object in the session you have to include the session declaration before checking the session.

Thats it. There is not much else
//
:-)
maybee more easy than I think

So every site I want to be a loginsite I give the page check session syntax in top... ??

The database and the privat data "automatic" shows the content from the database on site after the ID - login ?

the database is not controlling anything only content - it is the top code syntax who does the login work ?? :-)))
Post Reply