PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
silverme
Forum Newbie
Posts: 13 Joined: Tue Sep 27, 2005 4:24 pm
Post
by silverme » Sat Oct 01, 2005 2:09 am
This short test.php is to give a login acess. Once logged in, errMsg shows SECCESS and the session MM_Username will be shown; a FAILED is shown if it's given wrong login info. All code is created by Dreamweaver 2004 MX and I didn't modify any code inside.
Now I start to test it. I input a pair of username and password which is loaded in the database before. Enter. errMsg shows SECCESS but the value of session MM_Username never ever shows up. What can I do? (I tested to input incorrect username and/or password, errMsg did show FAILED when there were wrong. So the database connection should probabiy be no problem.)
Thank you
Code: Select all
<?php require_once('../Connections/IBGY.php'); ?>
<?php
// *** Start the session
session_start();
// *** Validate request to log in to this site.
$FF_LoginAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING']) && $HTTP_SERVER_VARS['QUERY_STRING']!="") $FF_LoginAction .= "?".$HTTP_SERVER_VARS['QUERY_STRING'];
if (isset($HTTP_POST_VARS['textfield1'])) {
$FF_valUsername=$HTTP_POST_VARS['textfield1'];
$FF_valPassword=$HTTP_POST_VARS['textfield2'];
$FF_fldUserAuthorization="";
$FF_redirectLoginSuccess="test.php?errMsg=Success";
$FF_redirectLoginFailed="test.php?errMsg=Failed";
$FF_rsUser_Source="SELECT lg_username, lg_password ";
if ($FF_fldUserAuthorization != "") $FF_rsUser_Source .= "," . $FF_fldUserAuthorization;
$FF_rsUser_Source .= " FROM logon WHERE lg_username='" . $FF_valUsername . "' AND lg_password='" . $FF_valPassword . "'";
mysql_select_db($database_IBGY, $IBGY);
$FF_rsUser=mysql_query($FF_rsUser_Source, $IBGY) or die(mysql_error());
$row_FF_rsUser = mysql_fetch_assoc($FF_rsUser);
if(mysql_num_rows($FF_rsUser) > 0) {
// username and password match - this is a valid user
$MM_Username=$FF_valUsername;
session_register("MM_Username");
if ($FF_fldUserAuthorization != "") {
$MM_UserAuthorization=$row_FF_rsUser[$FF_fldUserAuthorization];
} else {
$MM_UserAuthorization="";
}
session_register("MM_UserAuthorization");
if (isset($accessdenied) && false) {
$FF_redirectLoginSuccess = $accessdenied;
}
mysql_free_result($FF_rsUser);
session_register("FF_login_failed");
$FF_login_failed = false;
header ("Location: $FF_redirectLoginSuccess");
exit;
}
mysql_free_result($FF_rsUser);
session_register("FF_login_failed");
$FF_login_failed = true;
header ("Location: $FF_redirectLoginFailed");
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>TEST</title>
</head>
<body>
<form name="form1" method="POST" action="<?php echo $FF_LoginAction?>">
username:
<input name="textfield1" type="text" id="textfield1">
Password:
<input name="textfield2" type="text" id="textfield2">
<input type="submit" name="Submit" value="Login">
<?php echo $_GET['errMsg']; ?>
</form>
<?php echo $_SESSION['MM_Username']; ?>
</body>
</html>
silverme
Forum Newbie
Posts: 13 Joined: Tue Sep 27, 2005 4:24 pm
Post
by silverme » Sat Oct 01, 2005 2:24 am
Then I tried to put a small piece of code in it but the whole file was just not working after adding the following code in the file:
Code: Select all
<?php
if (isset($HTTP_SESSION_VARS[`MM_Username`])){echo 'COOOOOOOLLLLLL'};
?>
What's wrong?
ruchit
Forum Commoner
Posts: 53 Joined: Mon Sep 26, 2005 6:03 am
Post
by ruchit » Sat Oct 01, 2005 2:42 am
try printing the value of $MM_Username before session_register("MM_Username");
and for this
Code: Select all
if (isset($HTTP_SESSION_VARS[`MM_Username`])){echo 'COOOOOOOLLLLLL'};
//use semi-colon inside curly braces
if (isset($_SESSION[`MM_Username`])){echo 'COOOOOOOLLLLLL';}
silverme
Forum Newbie
Posts: 13 Joined: Tue Sep 27, 2005 4:24 pm
Post
by silverme » Sat Oct 01, 2005 5:05 pm
ok, after adding the semi-colon, the code works but the session value is still not shown. I added a Log Out function by DreamWeaver some values to echo on the page but this is the output after I logged on.
"
Success
MM: FF:session:/test/test.php?FF_Logoutnow=1
log out
"
Most values of variables are just not shown.
Code: Select all
<?php require_once('../Connections/IBGY.php'); ?>
<?php
// *** Logout the current user.
$FF_Logout = $HTTP_SERVER_VARS['PHP_SELF'] . "?FF_Logoutnow=1";
if (isset($HTTP_GET_VARS['FF_Logoutnow']) && $HTTP_GET_VARS['FF_Logoutnow']=="1") {
session_start();
session_unregister("MM_Username");
session_unregister("MM_UserAuthorization");
$FF_logoutRedirectPage = "test.php";
// redirect with URL parameters (remove the "FF_Logoutnow" query param).
if ($FF_logoutRedirectPage == "") $FF_logoutRedirectPage = $HTTP_SERVER_VARS['PHP_SELF'];
if (!strpos($FF_logoutRedirectPage, "?") && $HTTP_SERVER_VARS['QUERY_STRING'] != "") {
$FF_newQS = "?";
reset ($HTTP_GET_VARS);
while (list ($key, $val) = each ($HTTP_GET_VARS)) {
if($key != "FF_Logoutnow"){
if (strlen($FF_newQS) > 1) $FF_newQS .= "&";
$FF_newQS .= $key . "=" . urlencode($val);
}
}
if (strlen($FF_newQS) > 1) $FF_logoutRedirectPage .= $FF_newQS;
}
header("Location: $FF_logoutRedirectPage");
exit;
}
// *** Start the session
session_start();
// *** Validate request to log in to this site.
$FF_LoginAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING']) && $HTTP_SERVER_VARS['QUERY_STRING']!="") $FF_LoginAction .= "?".$HTTP_SERVER_VARS['QUERY_STRING'];
if (isset($HTTP_POST_VARS['textfield1'])) {
$FF_valUsername=$HTTP_POST_VARS['textfield1'];
$FF_valPassword=$HTTP_POST_VARS['textfield2'];
$FF_fldUserAuthorization="";
$FF_redirectLoginSuccess="test.php?errMsg=Success";
$FF_redirectLoginFailed="test.php?errMsg=Failed";
$FF_rsUser_Source="SELECT lg_username, lg_password ";
if ($FF_fldUserAuthorization != "") $FF_rsUser_Source .= "," . $FF_fldUserAuthorization;
$FF_rsUser_Source .= " FROM logon WHERE lg_username='" . $FF_valUsername . "' AND lg_password='" . $FF_valPassword . "'";
mysql_select_db($database_IBGY, $IBGY);
$FF_rsUser=mysql_query($FF_rsUser_Source, $IBGY) or die(mysql_error());
$row_FF_rsUser = mysql_fetch_assoc($FF_rsUser);
if(mysql_num_rows($FF_rsUser) > 0) {
// username and password match - this is a valid user
$MM_Username=$FF_valUsername;
session_register("MM_Username");
if ($FF_fldUserAuthorization != "") {
$MM_UserAuthorization=$row_FF_rsUser[$FF_fldUserAuthorization];
} else {
$MM_UserAuthorization="";
}
session_register("MM_UserAuthorization");
if (isset($accessdenied) && false) {
$FF_redirectLoginSuccess = $accessdenied;
}
mysql_free_result($FF_rsUser);
session_register("FF_login_failed");
$FF_login_failed = false;
header ("Location: $FF_redirectLoginSuccess");
exit;
}
mysql_free_result($FF_rsUser);
session_register("FF_login_failed");
$FF_login_failed = true;
header ("Location: $FF_redirectLoginFailed");
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>TEST</title>
</head>
<body>
<form name="form1" method="POST" action="<?php echo $FF_LoginAction?>">
username:
<input name="textfield1" type="text" id="textfield1">
Password:
<input name="textfield2" type="text" id="textfield2">
<input type="submit" name="Submit" value="Login">
<?php echo $_GET['errMsg']; ?>
</form>
<?php
echo "MM:",$MM_Username," ","FF:",$FF_valUsername,"session:";
if (isset($HTTP_SESSION_VARS[`MM_Username`])) {echo 'COOOOOOOLLLLLL';};
echo $FF_valUsername,$FF_valPassword,$FF_Logout;
?>
<p><?php echo $_SESSION['MM_Username']; ?>
</p>
<p><a href="<?php echo $FF_Logout ?>">log out</a> </p>
</body>
</html>
silverme
Forum Newbie
Posts: 13 Joined: Tue Sep 27, 2005 4:24 pm
Post
by silverme » Sun Oct 02, 2005 11:14 am
hmm..push this problem up.
So is the code fine? I started php last week and am still not so familiar with it. Why is such those problems accur?
Thank you all