By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,950 Members | 989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,950 IT Pros & Developers. It's quick & easy.

Php Login Page User Authentication Issue

P: 2
I have created a php login page in my site for my company. The goal is to get people into members area. Below is a list of steps that I take to create my login page in Dreamweaver CS3, can some one verify that I have built the page correct and that is nothing wrong with the code. If there is something wrong with the code is it possible to explain a step by step process to have a successful login page as I am new to creting php codes and pages in dreamweaver.

1.create new dynamic php page
2. create form tab
3. insert 2 text fields with a submit button
4. connect to the database on the web server
5.select form
6. add server behavior >user authentication>login user
7.follow the wizard to connect the database to form
8. server behavior created

with an action:<?php echo $loginFormAction; ?>

9. save and upload page to website
10. test page with login
11. page fails and selects the same page started not going to correct links if logged on properly.

Below is the code for my login page. Please tell me if there is a problem with the code or the action.

Expand|Select|Wrap|Line Numbers
  1. <?php require_once('Connections/user.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  5. {
  6.   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  7.  
  8.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  9.  
  10.   switch ($theType) {
  11.     case "text":
  12.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  13.       break;    
  14.     case "long":
  15.     case "int":
  16.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  17.       break;
  18.     case "double":
  19.       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  20.       break;
  21.     case "date":
  22.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  23.       break;
  24.     case "defined":
  25.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  26.       break;
  27.   }
  28.   return $theValue;
  29. }
  30. }
  31. ?>
  32. <?php
  33. // *** Validate request to login to this site.
  34. if (!isset($_SESSION)) {
  35.   session_start();
  36. }
  37.  
  38. $loginFormAction = $_SERVER['PHP_SELF'];
  39. if (isset($_GET['accesscheck'])) {
  40.   $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  41. }
  42.  
  43. if (isset($_POST['User Name'])) {
  44.   $loginUsername=$_POST['User Name'];
  45.   $password=$_POST['Password'];
  46.   $MM_fldUserAuthorization = "";
  47.   $MM_redirectLoginSuccess = "welcome.php";
  48.   $MM_redirectLoginFailed = "index.php";
  49.   $MM_redirecttoReferrer = false;
  50.   mysql_select_db($database_user, $user);
  51.  
  52.   $LoginRS__query=sprintf("SELECT `User Name`, Password FROM table1 WHERE `User Name`=%s AND Password=%s",
  53.     GetSQLValueString($loginUsername, "-1"), GetSQLValueString($password, "text")); 
  54.  
  55.   $LoginRS = mysql_query($LoginRS__query, $user) or die(mysql_error());
  56.   $loginFoundUser = mysql_num_rows($LoginRS);
  57.   if ($loginFoundUser) {
  58.      $loginStrGroup = "";
  59.  
  60.     //declare two session variables and assign them
  61.     $_SESSION['MM_Username'] = $loginUsername;
  62.     $_SESSION['MM_UserGroup'] = $loginStrGroup;          
  63.  
  64.     if (isset($_SESSION['PrevUrl']) && false) {
  65.       $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];    
  66.     }
  67.     header("Location: " . $MM_redirectLoginSuccess );
  68.   }
  69.   else {
  70.     header("Location: ". $MM_redirectLoginFailed );
  71.   }
  72. }
  73. ?>
  74. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  75. <html xmlns="http://www.w3.org/1999/xhtml">
  76. <head>
  77. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  78. <title>Untitled Document</title>
  79. </head>
  80.  
  81. <body>
  82. <form action="<?php echo $loginFormAction; ?>" method="POST" name="form1" target="_self" id="form1">
  83.   <p>User Name
  84.     <input name="User Name" type="text" id="User Name" size="20" maxlength="20" />
  85. </p>
  86.   <p>Password
  87.     <input name="Password" type="password" id="Password" size="20" maxlength="20" />
  88. </p>
  89.   <p>
  90.     <input type="submit" name="Submit" id="Submit" value="Login" />
  91.   </p>
  92. </form>
  93. </body>
  94. </html>
  95.  
Any help is appreciated!
Aug 31 '07 #1
Share this Question
Share on Google+
2 Replies


Atli
Expert 5K+
P: 5,058
Hi. Welcome to TSDN!

What exactly is the problem with your code?
Is it not behaving like you expect it to?
Are you receiving any errors?
Aug 31 '07 #2

P: 2
Hi. Welcome to TSDN!

What exactly is the problem with your code?
Is it not behaving like you expect it to?
Are you receiving any errors?


No, I put everything in correct and when I post my page to the website
I enter the username and password and it just joes to the same page it
was on. Meaning the action for the form isn't authenticating and sending
the correct user id and password to the right page.

Any help would be great!
Aug 31 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.