Jump to content

Mysql user login


waverider

Recommended Posts

Hello'
I have just swapped to a new host and a section of script no longer works. I think the problem is in the script below - using php 5.05 with the new host - 4.6 with the old one. The relevant functions are listed below the script.

The script returns 'The password you entered is incorrect' but user names and passwords in the database appear to be OK. Any assistance would be appreciated.

Thanks.



<?php

include('include_fns.php');

if ( (!isset($HTTP_POST_VARS['username'])) || (!isset($HTTP_POST_VARS['password'])) ) {
print 'You must enter your username and password to proceed';
exit;
}

$username = $HTTP_POST_VARS['username'];
$password = $HTTP_POST_VARS['password'];

if (login($username, $password)) {
$HTTP_SESSION_VARS['auth_user'] = $username;
header('Location: '.$HTTP_SERVER_VARS['HTTP_REFERER']);
}
else {
print 'The password you entered is incorrect';
exit;
}


?>
------------------------------------------------------------------------------------------
<?php
function login($username, $password)
// check username and password with db
// if yes, return true
// else return false
{
// connect to db
$conn = db_connect();
if (!$conn)
return 0;

$result = mysql_query("select * from writers
where username='$username'
and password = password('$password')");
if (!$result)
return 0;

if (mysql_num_rows($result)>0)
return 1;
else
return 0;
}

function check_auth_user()
// see if somebody is logged in and notify them if not
{
global $HTTP_SESSION_VARS;
if (isset($HTTP_SESSION_VARS['auth_user']))
return true;
else
return false;
}

function db_connect()
{
$result = @mysql_connect('localhost', 'db_user', 'password');
if (!$result)
return false;
if (!@mysql_select_db('db_name'))
return false;

return $result;

}

?>
Link to comment
https://forums.phpfreaks.com/topic/8030-mysql-user-login/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.