473,399 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Login system - help...

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..)

<?php
$host="my_host";
$username="";
$password="";
$db_name="member_db";
$tbl_name="members";

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

// Post data
$myusername=$_POST['theusername'];
$mypassword=$_POST['thepassword'];

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

//set session
session_register("myusername");
session_register("mypassword");
session_register("memkat");

if($memkat=="10"){
require("/path/to/folder/here1/index.php");
} elseif($memkat=="20"){
require("/path/to/folder/folder2/index.php");
} elseif($memkat=="30"){
require("/path/to/folder/folder3/index.php");
}
?>

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)

?>

Mar 19 '07 #1
3 1259
Nosferatum <Jo*********@gmail.comwrote:

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

//set session
session_start();
session_register("myusername");
session_register("mypassword");
session_register("memkat");
but as I just started to learn about sessions, we well both have to wait
for someone more expirienced :D

--
Ja NE
http://fotozine.org/?omen=janimir
--
Mar 19 '07 #2
Nosferatum wrote:
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..)

<?php
$host="my_host";
$username="";
$password="";
$db_name="member_db";
$tbl_name="members";

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

// Post data
$myusername=$_POST['theusername'];
$mypassword=$_POST['thepassword'];

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

//set session
session_register("myusername");
session_register("mypassword");
session_register("memkat");

if($memkat=="10"){
require("/path/to/folder/here1/index.php");
} elseif($memkat=="20"){
require("/path/to/folder/folder2/index.php");
} elseif($memkat=="30"){
require("/path/to/folder/folder3/index.php");
}
?>

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)

?>
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=$_SESSION['myusername']);
else
$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.
js*******@attglobal.net
==================
Mar 19 '07 #3
On Mar 19, 2:03 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Nosferatum wrote:
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..)
<?php
$host="my_host";
$username="";
$password="";
$db_name="member_db";
$tbl_name="members";
// Connection
mysql_connect("$host", "$username", "$password")or die("cannot
connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Post data
$myusername=$_POST['theusername'];
$mypassword=$_POST['thepassword'];
// query and get the memkat
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and
password='$mypassword'" and memkat="$memkat";
$result=mysql_query($sql);
//set session
session_register("myusername");
session_register("mypassword");
session_register("memkat");
if($memkat=="10"){
require("/path/to/folder/here1/index.php");
} elseif($memkat=="20"){
require("/path/to/folder/folder2/index.php");
} elseif($memkat=="30"){
require("/path/to/folder/folder3/index.php");
}
?>
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)
?>

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=$_SESSION['myusername']);
else
$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.
jstuck...@attglobal.net
==================
Jerry is right!

Within index page you have written:
Expand|Select|Wrap|Line Numbers
  1. <?php session_start(); ?>
  2. if (($myusername["musername"])) ;
  3. if (($mypassword["mypassword"]));
  4. if (($memkat["memkat"]));
  5.  
  6. include file(therealindex.php)
  7.  
You want to write:

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


Mar 21 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: buran | last post by:
Dear ASP.NET Programmers, How can I post data to an ASP.NET login page and pass authentication? The login page uses forms authentication, users must supply usernames and password and have to...
4
by: rrober07 | last post by:
Hello, My Setup is I have a Web Server machine(Devweb01), Database SQL Machine(Devsql01), a Client Machine(local machine) I have configured the SQL machine as follows: 1) Added local Aspnet...
2
by: pv | last post by:
Hi everyone, I need help with following scenario, please: Users are accessing same web server from intranet (users previously authenticated in Active Dir) and from extranet (common public...
0
by: muder | last post by:
I have a standard Login ASP.NET 2.0 control on a login Page, a LoginName and LoginStatus controls on the member's page. once the user login successfully I am redirecting the user to Member.aspx...
6
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.