Forum Moderators: coopster

Message Too Old, No Replies

Login script

         

Dhruv

5:36 pm on Sep 30, 2004 (gmt 0)

10+ Year Member



I've started making a guestbook and want to add an admin CP. Here is the relavent code. (Its adapted from what I've learnt at the tutorial)


function Show_Content()
{
session_start();

print "<html>
<head><title>Guestbook Administration </title></head>
<frameset cols='185, *' frameborder='no' border='0' framespacing='0'>
<frame name='menu' noresize scrolling='auto' src='?CODE=02&act=menu'>
<frame name='body' noresize scrolling='auto' src='?CODE=02&act=$index>
</frameset>
</html>";

}

function Show_Pages()
{
global $act, $CODE;
session_start();

$choice = array
(
"idx" => "idx",
"menu" => "menu"
);

if ($choice[$_GET['act']] == 'idx' ¦¦ $_GET['act'] == 'index')
{
Display_Content();
}
else if ($choice[$_GET['act']] == "menu")
{
Admin_Menu();
}
else
{
print "why the heck is this here?";
Do_Login();
}

}


OK, Before i ask the questions, let me just say this. Display_Content(), Admin_Menu() have just 2 lines

session_start();
and print statement
(for now).

As you can see, Show_Content() is called once the login has passed, the Show_Content() calls a framed page. Since i dont want to load pages as such (i want to load functions in the frames) I use the?CODE=02&act=menu/index

At the top of the script is a switch statement which basically calls Show_Pages() when it reads 02 from the URL. Using the 2nd query, the right function is shown.

All this works so far. Except for a hitch. Even though i dont login, i can directly access the URLs ...CODE=02&act=menu

Obviously this is not right. How do i make sure that the URL can't be accessed unless the session is active? I'm not using cookies and its kinda getting confused. How do i verify EACH time the user clicks on the link that he is who he says he is?

I've not posted the login code because i don want to confuse anyone. But If you think it'd help i'll post it.

Thanks

coopster

12:58 pm on Oct 4, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You will need to check the session information for that user on each page accessed to make sure they are logged in and authenticated. A common practice is to keep the authentication routine in a function. Then, that script with the authentication function is included at the very beginning of every page the user is attempting to access that requires the user to identify themself. If the user passes, OK, keep going and show the page. If not, redirect to you login.