$_SESSION Problems fo Newie and also URL Problem.
Posted: Wed Dec 01, 2004 3:58 am
patrikg | Help us, help you. Please use
then query it, it is here in the query i believe i have coded it wrong.
Full code is below and any help would be much appriacted? Also once i type in the url for login3.php page it re-directs be to another page 'login.php' which was an earlier attempt not sure why that is any help on that would be appriacted?
patrikg | Help us, help you. Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Hi guys im new to the world of php however i have produced a login script which is below. What i want the script to do is first of all check if a user exits? Check if they are validated?Check the rank which the user has? The problem is it logins in fine however it bypasses the two checks in my script. My understanding is that we first of all get the info needed out of the database i.eCode: Select all
$_SESSION['rank'] = $getUserInfo['rank'];Code: Select all
if ($_SESSION['rank'] = '2'){
Header ("Location: admin.php");
exit;
}Code: Select all
<?PHP
if ((isset($_POST['username'])) && (isset($_POST['password'])))
{
$db_conn = mysql_connect('localhost', 'mmc01ms', 'Debug+79');
mysql_select_db('dbfunkymonkey', $db_conn);
//Check to see if they left either the userName field or passWord field empty.
$dbQuery = mysql_query("SELECT * FROM customers WHERE username='".$_POST['username']."'",$db_conn);
$getUserInfo = mysql_fetch_array($dbQuery);
if($_POST['password'] == $getUserInfo['password'])
{
//register some varibles.
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
$_SESSION['rank'] = $getUserInfo['rank'];
$_SESSION['first_name'] = $getUserInfo['first_name'];
$_SESSION['validated'] = $getUserInfo['validated'];
$_SESSION['surname'] = $getUserInfo['surname'];
echo "Welcome, ".$_SESSION['first_name']." ".$_SESSION['surname']." using login name: ".$_SESSION['username']."<br />";
echo "<a href="index.php?action=logout">Logout</a>";
}
}
if ($_SESSION['rank'] = '2'){
Header ("Location: admin.php");
exit;
}
if ($_SESSION['validated'] = 0){
echo 'You must Validate your account';
exit;
}
if ((!isset($_POST['username'])) && (!isset($_POST['password'])))
{
echo "You are not currently logged in.<p>
<form name="auth" method="post" action="index.php?action=login">
Username: <input class="textfield" type="text" name="username" size="7">
Password: <input class="textfield" type="password" name="password" size="7">
<input type="hidden" name="action" value="login">
<input class="button" type="submit" name="Submit" value="Login">
<a href="register.php">Register</a>
</form>";
}
if (action == "logout")
{
session_destroy();
header("Location: login3.php");
exit;
break;
}
?>Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]