well.. i dunno about you guys..
but imho, there's nothing wrong
about putting the session_start() in the middle..
or anywhere..
as long as you dont start it twice
look carefully at his/her code..
what he's trying to do is that..
if the session is ok.. ONLY then start the session..
i guess if you ask em to put the session start
in the beginning of the code..
then, the login would render useless..
anyway shariff dude..
here's some of my opinion..
to be safe.. u should impose the username only to use valid chars..
perhaps by using eregi function, so you dont have to use stripslash in your login..
it is advisable not to use the session_register()
instead, use the superglobal array way..
it's much cooler, and it works swell..
which is $_SESSION['register']
checkout the manual.. http://www.php.net/manual/en/ref.session.php
i alter ur code on the fly..
dunno if it works or not..
you probably have to ammend it a bit..
but hope it gave some basic idea..
<?php
//set the database connection variables
$dbHost = "localhost";
$dbUser = "user";
$dbPass = "pw";
$dbDatabase = "db";
$user = $_POST['text_login']; //from username textfield at the login form
$password = $_POST['text_password']; //from password textfield at the login form
//connect to the database
$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
//Begin SQL
$query = "SELECT password FROM staff WHERE username='$user'";
// to do the above, you got to make sure that username is unique, and no 2 username are alike
// this could be imposed during user user registration...
$result = mysql_db_query($dbDatabase, $query);
$myinfo = mysql_fetch_array($result);
$total_found = mysql_num_rows($result);
if ($total_found == "0") {
echo "Incorrect login name or password. Please try again.";
} else {
$my_password = $myinfo['password'];
// the password from ur db, and its md5ed
$md5_password = md5($password);
// validating for a match
if ($md5_password == $my_password) {
session_start();
$_SESSION['register'] = $user;
echo "Login Successfull!";
} else {
echo "Incorrect login name or password. Please try again.";
}
}
?>
hope that helps...
tell me how it turn out eh..
till then.. take care m8
-jassh