473,466 Members | 1,430 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

php mysql authentication problem! help

1 New Member
Hi Guys

I have created a website and to makes things easier i decided to use dreamweaver to do the secure login section and access levels for the pages.

When testing locally on wamp my website works perfectly. On internet though, the pages that don't require a user to log in i can search my job database perfectly and see the results so the connection to the database is fine.

When i try to log in though i just get a user is unauthorised error because for some reason its not getting the info from the right database or the right table on the database or the connection is not right im not sure. I have emailed my support and they say they can't see an error with the connection dbusername dbpass dbname and suggest its a problem with my code somewhere.

It works perfectly on my local machine though arghhh!! Below is some of the code from the wizard.php page that was created in the /connections folder by dreamweaver. It all looks correct to me.

$[PHP] hostname_Wizard = "mysqlservername";

$database_Wizard = "mydatabasename";

$username_Wizard = "mysqlusername";

$password_Wizard = "mysqlpassword";

$Wizard = mysql_pconnect($hostname_Wizard, $username_Wizard, $password_Wizard) or trigger_error(mysql_error(),E_USER_ERROR);

Below is code from the page where the user will log in located above the head tag.

<?php require_once('Connections/Wizard.php'); ?>

<?php

//initialize the session

session_start();



// ** Logout the current user. **

$logoutAction = $ SERVER['PHP_SELF']."?doLogout=true";

if ((isset( $ SERVER['QUERY_STRING'])) && ( $ SERVER['QUERY_STRING'] != "")){

$logoutAction .="&". htmlentities( $ SERVER['QUERY_STRING']);

}



if ((isset( $ GET['doLogout'])) &&( $ GET['doLogout']=="true")){

//to fully log out a visitor we need to clear the session varialbles

session_unregister('MM_Username');

session_unregister('MM_UserGroup');



$logoutGoTo = "stafflogin.php";

if ($logoutGoTo) {

header("Location: $logoutGoTo");

exit;

}

}

?>

<?php

// *** Validate request to login to this site.

if (!isset( $ SESSION)) {

session_start();

}



$loginFormAction = $ SERVER['PHP_SELF'];

if (isset( $ GET['accesscheck'])) {

$ SESSION['PrevUrl'] = $ GET['accesscheck'];

}



if (isset( $ POST['username2'])) {

$loginUsername= $ POST['username2'];

$password= $ POST['password2'];

$MM_fldUserAuthorization = "accesslevel";

$MM_redirectLoginSuccess = "securestaff.php";

$MM_redirectLoginFailed = "unauthorised.php";

$MM_redirecttoReferrer = true;

mysql_select_db($database_Wizard, $Wizard);



$LoginRS__query=sprintf("SELECT name, pass, accesslevel FROM staff WHERE name='%s' AND pass='%s'",

get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));



$LoginRS = mysql_query($LoginRS__query, $Wizard) or die(mysql_error());

$loginFoundUser = mysql_num_rows($LoginRS);

if ($loginFoundUser) {



$loginStrGroup = mysql_result($LoginRS,0,'accesslevel');



//declare two session variables and assign them

$ SESSION['MM_Username'] = $loginUsername;

$ SESSION['MM_UserGroup'] = $loginStrGroup;



if (isset( $ SESSION['PrevUrl']) && true) {

$MM_redirectLoginSuccess = $ SESSION['PrevUrl'];

}

header("Location: " . $MM_redirectLoginSuccess );

}

else {

header("Location: ". $MM_redirectLoginFailed );

}

}

?>

[/PHP]

Below is code from the body of the page at the login boxes.



[HTML] <form action="<?php echo $loginFormAction; ?>" method="POST">

<table width="271" border="0" cellspacing="2" cellpadding="1">

<tr>

<td width="96" bgcolor="#EAEAEA"><label>Username:</label></td>

<td width="120"><input type="text" name="username2" size="20" /></td>

<td width="41">&nbsp;</td>

</tr>

<tr>

<td bgcolor="#EAEAEA"><label>Password: </label></td>

<td><input type="password" name="password2" size="20" /></td>

<td>&nbsp;</td>

</tr>

<tr>

<td bgcolor="#EAEAEA">Log In:</td>

<td><input type="submit" value=" Log In " /></td>

<td>&nbsp;</td>

</tr>

</table>

</form>

[/HTML]

Below is some code from the page that works it all out.



[PHP] <?php

//initialize the session

session_start();



// ** Logout the current user. **

$logoutAction = $ SERVER['PHP_SELF']."?doLogout=true";

if ((isset( $ SERVER['QUERY_STRING'])) && ( $ SERVER['QUERY_STRING'] != "")){

$logoutAction .="&". htmlentities( $ SERVER['QUERY_STRING']);

}



if ((isset( $ GET['doLogout'])) &&( $ GET['doLogout']=="true")){

//to fully log out a visitor we need to clear the session varialbles

session_unregister('MM_Username');

session_unregister('MM_UserGroup');



$logoutGoTo = "index.php";

if ($logoutGoTo) {

header("Location: $logoutGoTo");

exit;

}

}

?>

<?php

session_start();

$MM_authorizedUsers = "administrator";

$MM_donotCheckaccess = "true";



// *** Restrict Access To Page: Grant or deny access to this page

function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {

// For security, start by assuming the visitor is NOT authorized.

$isValid = False;



// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.

// Therefore, we know that a user is NOT logged in if that Session variable is blank.

if (!empty($UserName)) {

// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.

// Parse the strings into arrays.

$arrUsers = Explode(",", $strUsers);

$arrGroups = Explode(",", $strGroups);

if (in_array($UserName, $arrUsers)) {

$isValid = true;

}

// Or, you may restrict access to only certain users based on their username.

if (in_array($UserGroup, $arrGroups)) {

$isValid = true;

}

if (($strUsers == "") && true) {

$isValid = true;

}

}

return $isValid;

}



$MM_restrictGoTo = "unauthorised.php";

if (!((isset( $ SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $ SESSION['MM_Username'], $ SESSION['MM_UserGroup'])))) {

$MM_qsChar = "?";

$MM_referrer = $ SERVER['PHP_SELF'];

if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";

if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)

$MM_referrer .= "?" . $QUERY_STRING;

$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);

header("Location: ". $MM_restrictGoTo);

exit;

}

?>

[/PHP] I know its a big ask but i would really appreciate some php gurus help here as im stuck because it all works perfectly on my local wampserver but not on the net.



Regards



Joseph
Jul 2 '06 #1
2 4267
ronverdonk
4,258 Recognized Expert Specialist
Before going through this bunch of code, have you ever traced the content of the important variables during processing, such as $LoginRS__query (contains the actual query with username and password) and the results from that query.

That must at least give you an answer to your hunch that the query is wrong or that the incorrect data base is used.

Ronald :cool:
Jul 21 '06 #2
bevort
53 New Member
I ran into a same kind of problem when having to reinstall my local developing machine. The code that worked before and still works on the net does noet work anymore. I found my solution in checking the PHP.INI file (working on a windows server) and the Apache server. Check your settings on your local machine and set them to your net server then you have the same area to develop in as your online site.

Major differances can be found in PHP.ini when using registor_globals are set on or off. the same goes for the session.save_path.

Changing your local setting may force you to rebuild parts of your code but you will be certain that the code will work on both servers now.

I also see 2 session_start() statements in your last page. This will generate 2 sessioncookies on the server. The code will work with the last and store variables in this one but the server will work with the 1st one. So going to another page and using session_start your browser will point to an empty session witn no login information.

Another this is to keep things together. Keep only those part thah have to do with ligon in its own script and the logout parts in another. Afterwords put duplicate code into includefiles. This makes your files readable and maintainable even after several years.

Vincent
Jul 30 '06 #3

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

Similar topics

0
by: ME | last post by:
Just thought I would post a solution (temporary at best, but a solution at least.) for all those using PostNuke who have upgraded MySql to 4.1. I have had problems with PostNuke logging into MySql...
2
by: yzzzzz | last post by:
Hi I just upgraded from MySQL 4.0.something to 4.1.1 (alpha). When I try to connect to MySQL in a PHP script, I get the following error: "mysql_connect(): Client does not support...
11
by: John Victor | last post by:
In my mysql database, I've stored all the passwords using the PASSWORD() function. Now I'm running a test and need to compare the password in my php document to that saved in the database. I used...
1
by: Thomas | last post by:
Hallo. Habe auf einem SeSE 9.1 Server due neue MySQL 4.1.11 und den dazugehörigen client installiert. #: mysql -V mysql Ver 14.7 Distrib 4.1.11, for pc-linux-gnu (i686) Soweit so gut der...
1
by: Dmitry Davletbaev | last post by:
Hi! I'm working on program that acts as MySQL client. After successful connection program send queries for a long time. When I stop server mysql_query return error (no surprise). But when I...
2
by: marc.wyburn | last post by:
I'm writing a web app that needs a login page. I'm doing the dev on a windows box although the final version will go on a Linux box. I can't find any versions of mod_auth_Mysql precompiled for...
4
jepler
by: jepler | last post by:
I find myself in a circular reference loop that I can't seem to resolve. I recently upgraded from MySQL 4.0.x to MySQL 4.1.21 on OS 10.3.9 Server. Then, I *thought* I set my open master root password...
7
by: Paul | last post by:
I recently installed php 4.4.4 using windows binaries on Windows XP Pro. I also installed MySQL 4.1. I usually use Pear DB but I tried MDB2 and it worked fine until a client uses a different...
11
by: Robin S. | last post by:
I've used phpinfo() to confirm settings for mySQL on our host server, and it's not returning accurate info. phpinfo() returns a mySQL client API version of 3.23.54 (uselss for me), where as a...
0
JamieHowarth0
by: JamieHowarth0 | last post by:
I have been trying to find a solution to this on the Internet for months. Literally, ages and ages and ages, praying that someone in the open-source community has enough knowledge to put together an...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.