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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.