...

View Full Version : Access denied for user 'ODBC'@'localhost'



WWW_9hub_Net
01-15-2010, 09:44 AM
Hello Everyone,

I'm facing a problem and I would like to seek your help. I have downloaded a opensource php application to run on our company intranet. First I would like to provide my complete environment details.

WAMP Server 2.0i
Php V 5.2.7 (downgraded from 5.3.0 to get rid off ereg deprecated errors)
My SQL 5.1.36
OS - Windows Server 2003 R2
Port - 8080 (80 is used by IIS)

I have setup 3 applications on my wampserver(Timesheet/Joomla/Facility Booking) . All the three apps are running well on my server. I have created 3 different users and 3 different databases.

However, my Timesheet application is not running from other computer in our network. Well it's running but not able to connect to database. I mentioned the warnings and notices below. I'm able to login to the phpmyadmin from other computer to that database. So I feel the problem is with php source code. I have never worked on php before and your help is much appreciated.

I think there is no problem with apache or my sql as I don't see any errors related to this. These are from php error log which are displayed when I access the app.
Warnings and Notice

[14-Jan-2010 18:30:11] PHP Notice: Undefined variable: dbexists in C:\wamp\www\timesheet\topmain.php on line 47

[14-Jan-2010 18:30:11] PHP Warning: mysql_query() [<a href='function.mysql-query'>function.mysql-query</a>]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\wamp\www\timesheet\leftmain.php on line 236

[14-Jan-2010 18:30:11] PHP Warning: mysql_query() [<a href='function.mysql-query'>function.mysql-query</a>]: A link to the server could not be established in C:\wamp\www\timesheet\leftmain.php on line 236

[14-Jan-2010 18:30:11] PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\timesheet\leftmain.php on line 243

[14-Jan-2010 18:30:11] PHP Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\wamp\www\timesheet\leftmain.php on line 266

[14-Jan-2010 18:30:11] PHP Warning: mysql_query() [<a href='function.mysql-query'>function.mysql-query</a>]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\wamp\www\timesheet\leftmain.php on line 330

[14-Jan-2010 18:30:11] PHP Warning: mysql_query() [<a href='function.mysql-query'>function.mysql-query</a>]: A link to the server could not be established in C:\wamp\www\timesheet\leftmain.php on line 330

[14-Jan-2010 18:30:11] PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\timesheet\leftmain.php on line 338

[14-Jan-2010 18:30:11] PHP Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\wamp\www\timesheet\leftmain.php on line 349

[14-Jan-2010 18:30:11] PHP Warning: mysql_query() [<a href='function.mysql-query'>function.mysql-query</a>]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\wamp\www\timesheet\timeclock.php on line 120

[14-Jan-2010 18:30:11] PHP Warning: mysql_query() [<a href='function.mysql-query'>function.mysql-query</a>]: A link to the server could not be established in C:\wamp\www\timesheet\timeclock.php on line 120

[14-Jan-2010 18:30:11] PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\timesheet\display.php on line 54

[14-Jan-2010 18:30:11] PHP Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\wamp\www\timesheet\display.php on line 320


I have attached all files related. Sorry for long post this thing is driving me nuts since a week. Thanks in advance. Have a great weekend.

Fumigator
01-15-2010, 05:40 PM
Well the PHP is crap because it's not handling errors very well, this is true, but the actual problem isn't the PHP code, it's the connection to the database and/or the database user.

WWW_9hub_Net
01-15-2010, 07:14 PM
Yes, I showed it to one of my friend and he has same opinion about the code.

Header.php is the file which is handling DB connection. Can anyone comment on the header.php code ? Is is well programmed ?

masterofollies
01-15-2010, 07:35 PM
Change the connection and it should work.

WWW_9hub_Net
01-15-2010, 07:44 PM
One of the user at other forum pointed out that the problem is with these lines in header.php


// grab the connecting IP address. //
$connecting_ip = get_ipaddress();
if (empty($connecting_ip)) {
return FALSE;
}


The function get_ipaddress is defined as below in functions.php


function get_ipaddress() {

if (empty($REMOTE_ADDR)) {
if (!empty($_SERVER) && isset($_SERVER['REMOTE_ADDR'])) {
$REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
}
else if (!empty($_ENV) && isset($_ENV['REMOTE_ADDR'])) {
$REMOTE_ADDR = $_ENV['REMOTE_ADDR'];
}
else if (@getenv('REMOTE_ADDR')) {
$REMOTE_ADDR = getenv('REMOTE_ADDR');
}
}
if (empty($HTTP_X_FORWARDED_FOR)) {
if (!empty($_SERVER) && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$HTTP_X_FORWARDED_FOR = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else if (!empty($_ENV) && isset($_ENV['HTTP_X_FORWARDED_FOR'])) {
$HTTP_X_FORWARDED_FOR = $_ENV['HTTP_X_FORWARDED_FOR'];
}
else if (@getenv('HTTP_X_FORWARDED_FOR')) {
$HTTP_X_FORWARDED_FOR = getenv('HTTP_X_FORWARDED_FOR');
}
}
if (empty($HTTP_X_FORWARDED)) {
if (!empty($_SERVER) && isset($_SERVER['HTTP_X_FORWARDED'])) {
$HTTP_X_FORWARDED = $_SERVER['HTTP_X_FORWARDED'];
}
else if (!empty($_ENV) && isset($_ENV['HTTP_X_FORWARDED'])) {
$HTTP_X_FORWARDED = $_ENV['HTTP_X_FORWARDED'];
}
else if (@getenv('HTTP_X_FORWARDED')) {
$HTTP_X_FORWARDED = getenv('HTTP_X_FORWARDED');
}
}
if (empty($HTTP_FORWARDED_FOR)) {
if (!empty($_SERVER) && isset($_SERVER['HTTP_FORWARDED_FOR'])) {
$HTTP_FORWARDED_FOR = $_SERVER['HTTP_FORWARDED_FOR'];
}
else if (!empty($_ENV) && isset($_ENV['HTTP_FORWARDED_FOR'])) {
$HTTP_FORWARDED_FOR = $_ENV['HTTP_FORWARDED_FOR'];
}
else if (@getenv('HTTP_FORWARDED_FOR')) {
$HTTP_FORWARDED_FOR = getenv('HTTP_FORWARDED_FOR');
}
}
if (empty($HTTP_FORWARDED)) {
if (!empty($_SERVER) && isset($_SERVER['HTTP_FORWARDED'])) {
$HTTP_FORWARDED = $_SERVER['HTTP_FORWARDED'];
}
else if (!empty($_ENV) && isset($_ENV['HTTP_FORWARDED'])) {
$HTTP_FORWARDED = $_ENV['HTTP_FORWARDED'];
}
else if (@getenv('HTTP_FORWARDED')) {
$HTTP_FORWARDED = getenv('HTTP_FORWARDED');
}
}
if (empty($HTTP_VIA)) {
if (!empty($_SERVER) && isset($_SERVER['HTTP_VIA'])) {
$HTTP_VIA = $_SERVER['HTTP_VIA'];
}
else if (!empty($_ENV) && isset($_ENV['HTTP_VIA'])) {
$HTTP_VIA = $_ENV['HTTP_VIA'];
}
else if (@getenv('HTTP_VIA')) {
$HTTP_VIA = getenv('HTTP_VIA');
}
}
if (empty($HTTP_X_COMING_FROM)) {
if (!empty($_SERVER) && isset($_SERVER['HTTP_X_COMING_FROM'])) {
$HTTP_X_COMING_FROM = $_SERVER['HTTP_X_COMING_FROM'];
}
else if (!empty($_ENV) && isset($_ENV['HTTP_X_COMING_FROM'])) {
$HTTP_X_COMING_FROM = $_ENV['HTTP_X_COMING_FROM'];
}
else if (@getenv('HTTP_X_COMING_FROM')) {
$HTTP_X_COMING_FROM = getenv('HTTP_X_COMING_FROM');
}
}
if (empty($HTTP_COMING_FROM)) {
if (!empty($_SERVER) && isset($_SERVER['HTTP_COMING_FROM'])) {
$HTTP_COMING_FROM = $_SERVER['HTTP_COMING_FROM'];
}
else if (!empty($_ENV) && isset($_ENV['HTTP_COMING_FROM'])) {
$HTTP_COMING_FROM = $_ENV['HTTP_COMING_FROM'];
}
else if (@getenv('HTTP_COMING_FROM')) {
$HTTP_COMING_FROM = getenv('HTTP_COMING_FROM');
}
}

// Gets the default ip sent by the user //

if (!empty($REMOTE_ADDR)) {
$direct_ip = $REMOTE_ADDR;
}

// Gets the proxy ip sent by the user //

$proxy_ip = '';
if (!empty($HTTP_X_FORWARDED_FOR)) {
$proxy_ip = $HTTP_X_FORWARDED_FOR;
} else if (!empty($HTTP_X_FORWARDED)) {
$proxy_ip = $HTTP_X_FORWARDED;
} else if (!empty($HTTP_FORWARDED_FOR)) {
$proxy_ip = $HTTP_FORWARDED_FOR;
} else if (!empty($HTTP_FORWARDED)) {
$proxy_ip = $HTTP_FORWARDED;
} else if (!empty($HTTP_VIA)) {
$proxy_ip = $HTTP_VIA;
} else if (!empty($HTTP_X_COMING_FROM)) {
$proxy_ip = $HTTP_X_COMING_FROM;
} else if (!empty($HTTP_COMING_FROM)) {
$proxy_ip = $HTTP_COMING_FROM;
}

// Returns the true IP if it has been found, else FALSE //

if (empty($proxy_ip)) {
// True IP without proxy
return $direct_ip;
} else {
$is_ip = preg_match('|^([0-9]{1,3}\.){3,3}[0-9]{1,3}|', $proxy_ip, $regs);
if ($is_ip && (count($regs) > 0)) {
// True IP behind a proxy
return $regs[0];
} else {
// Can't define IP: there is a proxy but we don't have
// information about the true IP
return FALSE;
}
}
}


Can anyone please help me to clean up this code ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum