Login system - help...

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
please be patient, I am a newbie..

I have three categories of members ($memkat).
Each member got their own unike username and password from mysql db
and all belong to one of the three categories of members.
My mission is to get each member to login and be redirected to a
specific page in a specific folder. It should not be possible for
members from memkat10 to access (index-file) in folder memkat20  and
so on.

My faboulus login and redirect page: (which doesn't work..)


// Connection
mysql_connect("$host", "$username", "$password")or die("cannot
mysql_select_db("$db_name")or die("cannot select DB");

// Post data

// query and get the memkat
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and
password='$mypassword'" and memkat="$memkat";

//set session

} elseif($memkat=="20"){
} elseif($memkat=="30"){

In each of the index files in the member folders I thought about
requesting the session data from the login page at top,

Each index file:

<?php session_start(); ?>
if (($myusername["musername"])) ;
if (($mypassword["mypassword"]));
if (($memkat["memkat"]));

include file(therealindex.php)


Re: Login system - help...

I think you have to start session in login script...

Quoted text here. Click to load it


Quoted text here. Click to load it

but as I just started to learn about sessions, we well both have to wait
for someone more expirienced :D


Re: Login system - help...

Nosferatum wrote:
Quoted text here. Click to load it

First of all, you need to call session_start() at the beginning of every  
page using sessions (before ANY output - even whitespace).  You're not  
calling it in your logon page.

Secondly, $_myusername["myusername"] isn't defined in your second page.  
  If you have display_errors enabled, you will get a warning message  
about an uninitialized variable.

Additionally, instead of using session_register, you should use the  
$_SESSION array, i.e.

$_SESSION['myusername'] = $myusername;
$_SESSION['mypassword'] = $mypassword;

etc.  (Note: it's not a good idea to store passwords in the session  
unless you really need them there).

Then when you want to use them, use

if (isset($_SESSION['myusername']))
   $myusername = null;

(which can be shortened to:

$myusername=isset($_SESSION('myusername') ? $_SESSION['myusername'] : null;

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Login system - help...

Quoted text here. Click to load it

Jerry is right!

Within index page you have written:

<?php session_start(); ?>
if (($myusername["musername"])) ;
if (($mypassword["mypassword"]));
if (($memkat["memkat"]));

include file(therealindex.php)

You want to write:

if ( !empty($_SESSION["musername"]) and !
empty($_SESSION["mypassword"]) and !empty($_SESSION["memkat"])) {
       include file(therealindex.php)
after implementing Jerry suggestions.

Site Timeline